Deploying Self-Hosted PocketBase Backend on Ubuntu

Deploying Self-Hosted PocketBase Backend on Ubuntu

What You’ll Need

Table of Contents

Provisioning Ubuntu and Installing PocketBase

PocketBase is an open-source backend written in Go that packages an embedded SQLite database, user authentication, file storage, and an administrative UI into a single standalone binary. Because it relies on SQLite, it runs blazingly fast while using a fraction of the system resources required by traditional stack architectures like PostgreSQL paired with Node.js or Django.

To start, log in to your VPS instance. If you need a reliable hosting provider, I recommend setting up a node on Hetzner VPS or DigitalOcean for strong single-core CPU performance, which directly impacts SQLite execution speed.

First, update your package index and install required system utilities:

sudo apt update && sudo apt upgrade -y
sudo apt install -y unzip curl wget nginx certbot python3-certbot-nginx

For security best practices, never run your application server directly under the root user. Create a dedicated system user named pocketbase with no login shell access:

sudo useradd -r -m -s /bin/false pocketbase

Next, construct the installation directory layout and log directories:

sudo mkdir -p /var/www/pocketbase
sudo mkdir -p /var/log/pocketbase
sudo mkdir -p /var/backups/pocketbase

Download the latest compiled release architecture. At the time of writing, version 0.22.20 is current. Adjust the version tag if a newer release exists:

cd /tmp
wget https://github.com/pocketbase/pocketbase/releases/download/v0.22.20/pocketbase_0.22.20_linux_amd64.zip
sudo unzip pocketbase_0.22.20_linux_amd64.zip -d /var/www/pocketbase/
rm pocketbase_0.22.20_linux_amd64.zip

Set appropriate ownership permissions across your deployment paths:

sudo chown -R pocketbase:pocketbase /var/www/pocketbase
sudo chown -R pocketbase:pocketbase /var/log/pocketbase
sudo chown -R pocketbase:pocketbase /var/backups/pocketbase
sudo chmod +x /var/www/pocketbase/pocketbase

💡 Fast-Track Your Project: Don’t want to configure this yourself? I build custom n8n pipelines and bots. Message me with code SYS3-HUGO.

Configuring Systemd for Process Management

Running PocketBase directly inside a temporary terminal multiplexer or terminal window is unreliable for long-term production. We need systemd to manage execution, start the application automatically upon server reboot, and restart the process instantly if an out-of-memory error or unexpected crash occurs.

Create a new service definition file under /etc/systemd/system/pocketbase.service:

sudo nano /etc/systemd/system/pocketbase.service

Paste the following full service configuration into the file:

[Unit]
Description=PocketBase Backend Service
After=network.target

[Service]
User=pocketbase
Group=pocketbase
Type=simple
LimitNOFILE=4096
Restart=always
RestartSec=5s
StandardOutput=append:/var/log/pocketbase/app.log
StandardError=append:/var/log/pocketbase/error.log
ExecStart=/var/www/pocketbase/pocketbase serve --http=127.0.0.1:8090 --dir=/var/www/pocketbase/pb_data

[Install]
WantedBy=multi-user.target

Save and close the file. Reload the systemd daemon to process your new unit configuration, enable auto-start on boot, and start the service immediately:

sudo systemctl daemon-reload
sudo systemctl enable pocketbase
sudo systemctl start pocketbase

Verify that the process is running smoothly on local port 8090:

sudo systemctl status pocketbase

To ensure your server storage remains clean over time as execution logs accumulate inside /var/log/pocketbase/app.log, consider configuring automated log retention. You can learn more about configuring log rotation strategies in our detailed guide on Setting Up Logrotate for Custom Linux Server Logs.

Configuring Nginx Reverse Proxy and SSL

Now that PocketBase is listening on 127.0.0.1:8090, you need to set up a reverse proxy using Nginx to handle public HTTP/HTTPS traffic, manage TLS termination, and proxy WebSockets for real-time data subscriptions.

Before creating the web server configuration, visit your domain registrar like Namecheap and point an A record for your domain (e.g., pb.yourdomain.com) to your server’s public IP address.

Create a dedicated Nginx configuration file:

sudo nano /etc/nginx/sites-available/pocketbase

Insert this complete server configuration block:

server {
    listen 80;
    listen [::]:80;
    server_name pb.yourdomain.com;

    client_max_body_size 100M;

    location / {
        proxy_pass http://127.0.0.1:8090;
        proxy_http_version 1.1;
        
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable the configuration by creating a symbolic link in the sites-enabled directory and unlink the default Nginx placeholder site:

sudo ln -s /etc/nginx/sites-available/pocketbase /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default

Test your syntax for configuration errors:

sudo nginx -t

If the syntax test passes, reload Nginx to apply changes:

sudo systemctl reload nginx

Now, provision a free Let’s Encrypt SSL certificate using Certbot to force secure HTTPS traffic across all client requests:

sudo certbot --nginx -d pb.yourdomain.com --non-interactive --agree-tos --email admin@yourdomain.com

Certbot automatically modifies /etc/nginx/sites-available/pocketbase to handle HTTP to HTTPS redirection and attach TLS paths. You can verify your setup by accessing https://pb.yourdomain.com/_/ in your browser to complete initial administrative account creation.

Production Hardening: Backups, Logging, and Webhooks

PocketBase stores all operational records inside a single SQLite database file along with WAL files inside the pb_data folder. Creating automated physical and application backups ensures operational resiliency.

Automated Backups Script

We will write a complete shell script that safely locks SQLite tables using the official CLI backup command and compresses data files for remote transmission or local archiving.

Create the script at /usr/local/bin/pocketbase-backup.sh:

sudo nano /usr/local/bin/pocketbase-backup.sh

Add the following complete script:

#!/bin/bash
set -euo pipefail

BACKUP_DIR="/var/backups/pocketbase"
DATA_DIR="/var/www/pocketbase/pb_data"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
ARCHIVE_PATH="${BACKUP_DIR}/pb_backup_${TIMESTAMP}.tar.gz"

mkdir -p "${BACKUP_DIR}"

tar -czf "${ARCHIVE_PATH}" -C "${DATA_DIR}" .

chown pocketbase:pocketbase "${ARCHIVE_PATH}"
chmod 600 "${ARCHIVE_PATH}"

find "${BACKUP_DIR}" -type f -name "pb_backup_*.tar.gz" -mtime +14 -delete

Make the script executable:

sudo chmod +x /usr/local/bin/pocketbase-backup.sh

Now, set up a daily Cron job running at 2:00 AM under the root user:

sudo crontab -e

Add this line to the bottom of your crontab file:

0 2 * * * /usr/local/bin/pocketbase-backup.sh > /dev/null 2>&1

Centralized Logging Architecture

In production workloads, plain file logging often becomes difficult to query. For enterprise monitoring, streaming structured application logs off your host machine enables real-time search and threshold alerting. If you plan to capture stdout/stderr from systemd and format it into structured JSON logs for Grafana Loki or Elasticsearch, check out our tutorial on Building Structured Log Pipelines with Fluent Bit.

Reliability for Outbound Webhooks

When extending your self-hosted backend using PocketBase Event Hooks (Go or JavaScript extensions) to trigger external automation platforms like n8n or Make, network partitions can cause data loss if external APIs fail.

When configuring event handlers to emit POST payloads outside your server environment, ensure your service scripts wrap network calls in resilient failure handlers. You can read our detailed implementation guide on Implementing Circuit Breakers for Outbound Webhook Delivery to prevent systemic cascade failures when downstream endpoints experience downtime.

Here is a full system test command to verify your HTTP REST endpoint responsiveness locally:

curl -i https://pb.yourdomain.com/api/health

You should receive an HTTP status output of 200 OK along with JSON metadata output:

{"code":200,"message":"API is healthy.","data":{}}

Your self-hosted PocketBase instance is now configured securely on Ubuntu, complete with systemd process management, SSL encryption, reverse proxying, automated daily backups, and robust database persistence.

Getting Started

Ready to deploy your self-hosted application stack? Spin up your high-performance server instance on Hetzner VPS or Contabo VPS. If you need cloud alternatives, consider DigitalOcean. Secure your custom application domain names quickly through Namecheap.

Outsource Your Automation

Don’t have time? I build production n8n workflows, WhatsApp bots, and fully automated YouTube Shorts pipelines. Hire me on Fiverr, mention SYS3-HUGO for priority. Or DM at chasebot.online.

Want to automate this yourself?

Start with n8n Cloud (free tier available) or self-host on a Hetzner VPS for full control.

Want this engine running on your own VPS?

This blog publishes itself — daily, unattended, on free API tiers. The full engine, Hugo theme, and setup guide are available as System 3.

Get System 3
system online