How to Deploy Pocketbase on a VPS: Single-File Backend for Web and Mobile Apps

How to Deploy Pocketbase on a VPS: Single-File Backend for Web and Mobile Apps

Pocketbase is an open-source backend in a single Go binary — it provides a SQLite-based database with a visual schema editor, a REST API auto-generated from your schema, realtime subscriptions, built-in authentication (email/password + OAuth2), file storage, and an admin dashboard. No Docker required. No runtime dependencies. One binary, one systemd service, and you have a complete backend for frontend or mobile apps.

What Pocketbase Includes

  • Database: SQLite with a visual collection builder — define fields, relations, and rules in the UI
  • REST API: CRUD endpoints auto-generated for every collection
  • Realtime: SSE-based subscriptions — push record changes to clients instantly
  • Authentication: Email/password, username, OAuth2 (Google, GitHub, Discord, etc.), two-factor auth
  • File storage: Upload files attached to records; serve locally or via S3
  • Admin UI: Web-based dashboard for managing records, users, API rules, and settings
  • Extensibility: JavaScript hooks or Go plugins for custom logic

Step 1: Download and Install Pocketbase

sudo mkdir -p /opt/pocketbase
sudo useradd --no-create-home --shell /bin/false pocketbase

# Check latest version at: https://github.com/pocketbase/pocketbase/releases
cd /tmp
wget https://github.com/pocketbase/pocketbase/releases/download/v0.23.6/pocketbase_0.23.6_linux_amd64.zip
unzip pocketbase_0.23.6_linux_amd64.zip
sudo mv pocketbase /opt/pocketbase/pocketbase
sudo chmod +x /opt/pocketbase/pocketbase
sudo chown -R pocketbase:pocketbase /opt/pocketbase

Step 2: Create systemd Service

sudo nano /etc/systemd/system/pocketbase.service
[Unit]
Description=Pocketbase Backend
After=network.target

[Service]
User=pocketbase
Group=pocketbase
WorkingDirectory=/opt/pocketbase
ExecStart=/opt/pocketbase/pocketbase serve \
  --http="127.0.0.1:8090" \
  --dir="/opt/pocketbase/pb_data"
Restart=on-failure
RestartSec=5s
StandardOutput=journal
StandardError=journal
MemoryMax=256M

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now pocketbase
sudo systemctl status pocketbase

Step 3: Nginx with SSL (WebSocket Support for Realtime)

sudo nano /etc/nginx/sites-available/pocketbase
server {
    listen 80;
    server_name api.yourdomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name api.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/api.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.yourdomain.com/privkey.pem;

    client_max_body_size 50M;

    location / {
        proxy_pass http://127.0.0.1:8090;
        proxy_http_version 1.1;

        # Required for SSE realtime subscriptions:
        proxy_set_header Connection '';
        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;

        # Long timeout for SSE connections
        proxy_read_timeout 3600s;
        proxy_buffering off;
        proxy_cache off;
    }
}
sudo ln -s /etc/nginx/sites-available/pocketbase /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d api.yourdomain.com

Step 4: Admin Dashboard Setup

  1. Visit https://api.yourdomain.com/_/ (note the trailing slash)
  2. Create your superadmin account (email + secure password)
  3. In Collections, create your first collection: define fields, set API rules
  4. In Settings, configure OAuth providers, SMTP, and storage options

Using Pocketbase from JavaScript

// Install: npm install pocketbase
import PocketBase from 'pocketbase';

const pb = new PocketBase('https://api.yourdomain.com');

// Authenticate user
const authData = await pb.collection('users').authWithPassword(
    'user@example.com', 'password123'
);

// Fetch records with filters, sorting, and relation expansion
const records = await pb.collection('posts').getList(1, 30, {
    filter: 'created >= "2024-01-01" && published = true',
    sort: '-created',
    expand: 'author',
});

// Create record
const newPost = await pb.collection('posts').create({
    title: 'Hello World',
    content: 'My first post',
    published: true,
});

// Realtime subscription — updates pushed instantly
pb.collection('messages').subscribe('*', (e) => {
    console.log(e.action);  // 'create', 'update', or 'delete'
    console.log(e.record);
});

// File upload
const formData = new FormData();
formData.append('avatar', avatarFile);
await pb.collection('users').update(pb.authStore.model.id, formData);

S3 File Storage for Large Uploads

  1. Pocketbase Admin → Settings → Files storage
  2. Enable S3, enter credentials for AWS S3, Cloudflare R2 (free egress), or Backblaze B2
  3. Files are stored in S3; metadata and records stay in SQLite on your VPS

Backup — It’s Just One Directory

# Backup everything (SQLite DB + uploaded files)
tar czf /opt/backups/pocketbase-$(date +%Y%m%d).tar.gz /opt/pocketbase/pb_data/

# Or use Pocketbase's built-in backup command
sudo -u pocketbase /opt/pocketbase/pocketbase backup \
  --dir=/opt/pocketbase/pb_data
# Creates a zip in pb_data/backups/

# Automate with cron
0 3 * * * tar czf /opt/backups/pb-$(date +\%Y\%m\%d).tar.gz \
  /opt/pocketbase/pb_data/ 2>/dev/null

Updating Pocketbase

sudo systemctl stop pocketbase
cd /tmp
wget https://github.com/pocketbase/pocketbase/releases/download/vNEW_VERSION/pocketbase_NEW_VERSION_linux_amd64.zip
unzip pocketbase_NEW_VERSION_linux_amd64.zip
sudo mv pocketbase /opt/pocketbase/pocketbase
sudo chown pocketbase:pocketbase /opt/pocketbase/pocketbase
sudo systemctl start pocketbase

Getting Started

Pocketbase uses 20–50 MB RAM at idle — one of the most resource-efficient backend options available. It runs alongside other services on the smallest Ubuntu VPS at VPS.DO. The single-file binary makes deployment trivial on any KVM VPS without Docker or language runtime dependencies.

Conclusion

Pocketbase provides a complete, production-capable backend — database, API, auth, realtime, and file storage — in a single binary using 20 MB RAM at idle. For indie developers, small teams, and prototype-to-production projects, it eliminates the need for Firebase or a separate API server. The Go binary runs on any Linux VPS, backs up to a single directory, and scales to tens of thousands of users before requiring architectural changes.

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!