In the previous blog post, I showed you how to write a JavaScript application talking to
PocketBase on the backend. In this post, I will show you how to deploy such
an application on a Debian 13 server using Caddy as a reverse proxy.
This guide assumes that a domain is already set up and pointing to the server IP address. I will use the domain todo.rasc.ch for this example.
It also assumes that the application has access to an SMTP server for sending emails. This could be a local SMTP server or an external one like Gmail, SendGrid, etc.
Architecture ¶
The application we will deploy in this guide consists of two parts: an Angular application compiled to static files and a PocketBase API server. Both parts will be served by the Caddy web server, which will act as a reverse proxy.
1. Server Preparation ¶
Update System ¶
To ensure the system is up to date, run the following command:
sudo apt update && sudo apt upgrade -y
Install Required Packages ¶
To install Caddy, follow the instructions from the official documentation.
If you want to build the Angular application on the server, you also need to install Node.js and npm.
This guide compiles the Angular application locally and uploads the static files to the server with scp.
We also need the unzip and wget packages to download and extract the PocketBase binary.
If not already installed, install them with the following command:
sudo apt install unzip wget -y
Create Application User ¶
For security reasons, it is a good practice to run the application under a dedicated user account.
Here we create a user named todo:
sudo useradd -m -s /bin/bash todo
sudo install -d -o todo -g caddy -m 2755 /srv/pockettodo
# Switch to application user
sudo su - todo
2. Deploy PocketBase ¶
Download and Setup PocketBase ¶
In this step, we create the home directory for our application and download PocketBase.
Make sure to run these steps as the todo user we created earlier.
This guide pins PocketBase v0.40.6, the latest release checked on October 23, 2026, together with JavaScript SDK v0.28.1 in the client project. Check the PocketBase homepage and release notes before a later deployment. The v0.40.6 release notes announce that future releases are moving away from GitHub and that pocketbase update now fetches releases from https://ganigeorgiev.com. The GitHub download below is for this specific release.
The pocketbase folder will contain the PocketBase binary including the pb_data and pb_migrations directories.
The static Angular files go in /srv/pockettodo. Caddy recommends /srv or /var/www/html for its systemd service because serving files from a user home directory can fail due to traversal permissions. Keep uploaded files readable by the caddy user.
mkdir -p /home/todo/pocketbase
mkdir -p /home/todo/pocketbase/pb_migrations
cd /home/todo/pocketbase
# Download PocketBase (check the releases page before copying this command)
# Make sure to download the correct version for your architecture
PB_VERSION="0.40.6"
wget https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip
unzip pocketbase_${PB_VERSION}_linux_amd64.zip
chmod +x pocketbase
rm pocketbase_${PB_VERSION}_linux_amd64.zip
mkdir -p pb_data
Create PocketBase Systemd Service ¶
Return to your administrator shell with exit. Run the remaining sudo commands from that account; the todo service account does not need sudo privileges. To run PocketBase as a service, create a systemd service file.
sudo nano /etc/systemd/system/pocketbase.service
Add the following content:
[Unit]
Description=PocketBase
After=network.target
[Service]
Type=simple
User=todo
Group=todo
LimitNOFILE=4096
WorkingDirectory=/home/todo/pocketbase
ExecStart=/home/todo/pocketbase/pocketbase serve --http=127.0.0.1:9999
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=pocketbase
# Security settings
NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
ReadWritePaths=/home/todo/pocketbase
[Install]
WantedBy=multi-user.target
Enable PocketBase Service ¶
Next, enable the PocketBase service so it runs on server startup.
# Reload systemd and enable service
sudo systemctl daemon-reload
sudo systemctl enable pocketbase
3. Deploy Angular Application ¶
Build Application Locally ¶
In the Angular application, set the production environment to point to the PocketBase API URL.
export const environment = {
production: true,
pocketbaseUrl: 'https://todo.rasc.ch'
};
From the companion project's todo directory, install the pinned dependencies and build the application:
npm install
npm run build
Copy the files in the dist/app/browser directory to the server. To check the backend before deployment, place the v0.40.6 executable in the parent pockettodo directory and run npm run test:pocketbase. This starts an isolated server and verifies migrations, authentication, todo operations, and access rules using temporary data.
Upload to Server ¶
# From your local machine, upload the built files
scp -r dist/app/browser/* todo@your-server-ip:/srv/pockettodo/
# Or using rsync
rsync -avz --delete dist/app/browser/ todo@your-server-ip:/srv/pockettodo/
4. Configure Caddy ¶
Create Caddyfile ¶
In this step, we create the Caddy configuration file to serve the Angular application and reverse proxy requests to the PocketBase API.
sudo nano /etc/caddy/Caddyfile
Add the following configuration:
todo.rasc.ch {
encode gzip
header {
Strict-Transport-Security "max-age=31536000"
X-Frame-Options "DENY"
X-Content-Type-Options "nosniff"
Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' https://todo.rasc.ch/api;"
}
# Keep API and PocketBase auth/dashboard routes out of the SPA fallback.
handle /api/* {
reverse_proxy 127.0.0.1:9999
}
handle /_/* {
reverse_proxy 127.0.0.1:9999
}
handle {
root * /srv/pockettodo
try_files {path} /index.html
header Cache-Control "no-cache"
file_server
}
log {
output file /var/log/caddy/todo.rasc.ch.log {
roll_size 10MiB
roll_keep 30
roll_keep_for 720h
}
}
}
The SPA fallback makes direct links and browser refreshes on Angular routes work. no-cache allows storage but requires revalidation, so an update does not leave users with stale HTML or unversioned assets. Longer caching can be added for files whose names contain content hashes.
Test and Reload Caddy Configuration ¶
# Test configuration
sudo caddy validate --config /etc/caddy/Caddyfile
# Reload Caddy
sudo systemctl reload caddy
# Check Caddy status
sudo systemctl status caddy
# View Caddy logs
sudo journalctl -u caddy -f
5. Configure PocketBase ¶
Copy Migrations ¶
Copy the migration files from the pb_migrations directory of your local PocketBase installation to the server.
scp -r /path/to/local/pocketbase/pb_migrations/* todo@your-server-ip:/home/todo/pocketbase/pb_migrations/
Now start PocketBase.
sudo systemctl start pocketbase
# Check status
sudo systemctl status pocketbase
# View logs
sudo journalctl -u pocketbase -f
Setup Admin Account ¶
In this step, we create the admin account for PocketBase.
sudo -iu todo
cd /home/todo/pocketbase
./pocketbase superuser create EMAIL PASS
exit
Alternatively, you can do this via the web interface when opening the PocketBase admin dashboard. You find the URL for this functionality in the systemd log file:
sudo journalctl -u pocketbase -f
Configure Settings ¶
Open the PocketBase admin dashboard and log in with the admin account you just created. Under Settings > Application, set the application name and URL.
- Application name: PocketTodo
- Application URL:
https://todo.rasc.ch
Under "User IP proxy headers", enter the header name that Caddy uses to forward the user's IP address to PocketBase.
- X-Forwarded-For:
X-Forwarded-For
Under Settings > Mail settings, configure the SMTP settings to enable email functionality.
- SMTP server: Your email provider's SMTP server
- Port: 587 (TLS) or 465 (SSL)
- Username: Your email address
- Password: Your email password or app-specific password
Enable rate limiting for better security. PocketBase has default rate limit rules, but they are not enabled by default. Check them to ensure they fit your needs and enable them.
Protect Administrative Access ¶
Keep the /_/* proxy route: PocketBase's default password-reset and verification links also use this path. Removing it breaks those flows and does not disable the administrative API. Protect superuser authentication using PocketBase's MFA and IP allowlist settings; see the production guide.
The superuser IP restriction is available under Settings > Application > Superuser IPs (added in v0.38). Configure the forwarded client IP header first, then allow the addresses or subnets from which you administer the server. If your address changes, the pocketbase superuser ips command can change or clear the restriction from the server shell.
6. Log Rotation ¶
The output file block above uses Caddy's built-in log rotation. It rotates at 10 MiB and retains at most 30 rolled files for up to 30 days. Use Caddy's rotation for this file without an additional logrotate configuration.
7. Backup ¶
Backups are crucial for a production application. You should regularly back up the PocketBase database.
Open the admin dashboard. In my case, it is https://todo.rasc.ch/_/. Then open the Settings > Backups menu
and enable auto backups by entering a cron expression and the number of backups to keep.
Also enable the "Store backups in S3 storage" option, which stores the backup in an S3-compatible storage
away from the server. This is a good practice to ensure that backups are not lost if the server fails.
When using the S3 option, it is recommended to use a separate bucket only for backups. The generated backup
contains the database and locally uploaded files from pb_data, excluding local backup archives and files stored in S3. Back up S3 uploads separately.
Since v0.40.0, backup generation no longer locks the database for the duration of the backup. Queries can still slow down while it runs. PocketBase v0.39 also added email alerts to superusers when automated backups fail, so configure and test SMTP delivery.
8. Deployment Updates ¶
Updating the application is straightforward. Unless your client application uses features that require a new PocketBase version, you can update them separately. If there are breaking changes in the PocketBase API, you may need to stop the PocketBase service, update the client application, update the PocketBase binary, and then start PocketBase again.
Update Angular Application ¶
# Build new version locally
npm run build
# Upload to server
rsync -avz --delete dist/app/browser/ todo@your-server-ip:/srv/pockettodo/
Updating just the Angular application does not require any service restarts, as Caddy serves static files directly.
Update PocketBase ¶
Read the release notes for every version between your installed release and v0.40.6, then test the update on a copy of your data. v0.40.0 changed JSON handling and now returns a nonzero exit code for failed console commands. Deployment scripts must stop when an update or migration fails. The v0.40.6 binary also includes updated dependencies and a limit on source-image pixels for thumbnail generation.
Start from your administrative account. Stop the service, then switch to todo to back up the matching binary, data, and migrations. Keep the backup outside the application directory. The following commands install the same pinned release used in this guide; check each command succeeds before continuing.
sudo systemctl stop pocketbase
sudo -iu todo
cd /home/todo/pocketbase
# Back up the stopped application to a new directory
BACKUP_DIR="/home/todo/pocketbase-backups/$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$BACKUP_DIR"
cp -a pocketbase pb_data pb_migrations "$BACKUP_DIR/"
# Download and install the pinned release (Linux x64)
PB_VERSION="0.40.6"
wget https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip
unzip -o pocketbase_${PB_VERSION}_linux_amd64.zip pocketbase
chmod +x pocketbase
./pocketbase --version
# Copy any new application migrations into pb_migrations before this step
./pocketbase migrate up
# Return to the administrator shell and start the service
exit
sudo systemctl start pocketbase
# Check status
sudo systemctl status pocketbase
sudo journalctl -u pocketbase -n 50 --no-pager
Check login, password reset, and creating, updating, and deleting a todo before considering the update complete. Keep the backup until these checks pass. To roll back, stop the service and restore the saved binary, pb_data, and pb_migrations together; running an older binary against an already migrated database is not a rollback.
For future releases, ./pocketbase update remains available, but from v0.40.6 onward it uses the new release host described above. Review and test the chosen release before updating production.
Conclusion ¶
This guide covers the complete process of deploying a JavaScript application with PocketBase on a production server.
If you have any questions or suggestions, feel free to send me a message.