How to Self-Host PocketBase
Learn how to self host pocketbase easily on your own production server, run it as a service with cron job backups
Snehasis Ghosh
How to Self-Host PocketBase
A step-by-step guide to deploying PocketBase on your own server.
Prerequisites
- A server or VPS (Ubuntu/Debian recommended)
- SSH access to the server
- Basic familiarity with the terminal
1. Download PocketBase
Visit pocketbase.io/docs and download the appropriate zip file for your system architecture:
- AMD/x64 — for most cloud VPS instances
- ARM64 — for ARM-based servers (e.g., Oracle Cloud free tier, Raspberry Pi)
# Example for Linux AMD64
wget https://github.com/pocketbase/pocketbase/releases/download/v0.x.x/pocketbase_0.x.x_linux_amd64.zip
unzip pocketbase_0.x.x_linux_amd64.zip -d /home/pocketbase
2. Run PocketBase
./pocketbase serve
By default it runs on http://localhost:8090. The admin UI is available at http://localhost:8090/_/.
If port 8090 is accessible from your browser, you can create a superuser directly through the UI on first launch.
3. Create a Superuser (CLI)
If you can't access the UI, create a superuser via the command line:
./pocketbase superuser upsert [email protected] yourpassword
4. Run on a Custom Domain
You can bind PocketBase to a custom domain with automatic HTTPS (via Let's Encrypt):
./pocketbase serve pb.example.com
Make sure your DNS A record points to the server's IP address.
5. Run as a Systemd Service
Create a service file so PocketBase starts automatically and restarts on failure.
sudo nano /etc/systemd/system/pocketbase.service
Paste the following:
[Unit]
Description=PocketBase
After=network-online.target
[Service]
Type=simple
User=pocketbase
WorkingDirectory=/home/pocketbase
ExecStart=/home/pocketbase/pocketbase serve --http=0.0.0.0:80
Restart=always
RestartSec=5
LimitNOFILE=4096
StandardOutput=append:/home/pocketbase/pb.log
StandardError=append:/home/pocketbase/pb.log
[Install]
WantedBy=multi-user.target
Enable and start the service:
sudo systemctl enable pocketbase
sudo systemctl start pocketbase
sudo systemctl status pocketbase
6. Automated Backups to S3
Create a backup script that archives pb_data and uploads it to an S3 bucket using curl with AWS Signature V4.
sudo nano /home/pocketbase/backup.sh
#!/usr/bin/env bash
set -euo pipefail
# --- Configuration ---
PB_DATA_DIR="/opt/pocketbase/pb_data"
BACKUP_DIR="/opt/pocketbase/backups"
AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"
AWS_REGION="ap-south-1"
S3_BUCKET="your-backup-bucket"
S3_PREFIX="pocketbase"
# --- Script ---
TIMESTAMP="$(date +'%Y-%m-%d_%H-%M-%S')"
HOSTNAME="$(hostname -s)"
ARCHIVE_NAME="pb_data_${HOSTNAME}_${TIMESTAMP}.tar.gz"
ARCHIVE_PATH="${BACKUP_DIR}/${ARCHIVE_NAME}"
OBJECT_KEY="${S3_PREFIX}/${ARCHIVE_NAME}"
mkdir -p "$BACKUP_DIR"
tar -czf "$ARCHIVE_PATH" -C "$(dirname "$PB_DATA_DIR")" "$(basename "$PB_DATA_DIR")"
curl --fail --silent --show-error \
--aws-sigv4 "aws:amz:${AWS_REGION}:s3" \
--user "${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}" \
-T "$ARCHIVE_PATH" \
"https://${S3_BUCKET}.s3.${AWS_REGION}.amazonaws.com/${OBJECT_KEY}"
echo "✅ Uploaded to s3://${S3_BUCKET}/${OBJECT_KEY}"
Make it executable:
chmod +x /home/pocketbase/backup.sh
7. Schedule Backups with Cron
Run the backup daily at midnight:
crontab -e
Add this line:
0 0 * * * /home/pocketbase/backup.sh
Summary
| Step | What it does |
|---|---|
| Download & unzip | Get the PocketBase binary |
pocketbase serve | Start the server |
superuser upsert | Create admin credentials |
| Custom domain | HTTPS with Let's Encrypt |
| Systemd service | Auto-start & crash recovery |
| Backup script | Archive pb_data → S3 |
| Cron job | Automate daily backups |
Tip: For production, consider placing PocketBase behind a reverse proxy (Caddy or Nginx) for more control over TLS, rate limiting, and headers.
