PocketBase is promising and might fully win me over. I have been playing with it on a few small projects and I appreciate it's strengths now over SupaBase. I have nothing against SupaBase by the way, it just doesn't make sense for a small project to go with it given how bulky it is to host. The best bet is if you go with their managed option, in which case, you didn't leave Firebase, did yuh?
I am making this short tutorial for my future use, I find it easier to log onto my blog when deploying a docker app, and so if PocketBase becomes my fully go-to backend for the next few years, I might end up reading this article more times than you. (I am terrified AI makes blogging silly these days. Why would you come read this article when you can go to ChatGPT and ask "How to self-host PocketBase on a VPS?"). I have no idea why you are here, you probably like it better when someone vouches for a given approach. Well, I vouch for this installation process. Enough disclaimers.
First things First, Deploy a VPS
Need I mention that you need a working VPS for this? Pick any Linux server. I recommend DigitalOcean. However, I am becoming a fan of OVHCloud, though the process of deploying a server over there is not as straightforward as you'd expect. In fact, with OVHCloud, you'll have fun if you prefer setting up most things. For example, by default, the ssh login to your VPS is username and password đź©»That is dangerous. So I went ahead and disabled that after adding an ssh key. By the way, to add an SSH key, you only need to do:
ssh-copy-id {USER}@{SERVER_IP}
And then, as usual, ssh to the server and let's go!
Installing and Running PocketBase on a VPS with SSL (Let's Encrypt)
- Download PocketBase to your Linux VPS
curl -L -o pocketbase.zip https://github.com/pocketbase/pocketbase/releases/download/v0.21.3/pocketbase_0.21.3_linux_amd64.zip
- This downloads the specified version of PocketBase. To get the latest version, go to https://pocketbase.io/docs/, right click on the Linux download option and copy the link. In Curl, the -L
option tells curl to follow redirects, while the -o
option specifies the output file.
If you run the command at the home of your VPS user, the file will be downloaded to /home/{user}
so in my case, since I am using ubuntu
user, the download goes to /home/ubuntu
- Next, unzip the file to a folder called
pb
unzip pocketbase.zip -d pb
- Make PocketBase executable
chmod +x pb/pocketbase
- Allow PocketBase to access lower ports (so it can run on port 80 and 443 if you are using a domain)
sudo setcap 'cap_net_bind_service=+ep' /home/ubuntu/pb/pocketbase
- Create a service to manage PocketBase
sudo vim /lib/systemd/system/pocketbase.service
Add the following to the file.
[Unit]
Description = pocketbase
[Service]
Type = simple
User = ubuntu
Group = ubuntu
LimitNOFILE = 4096
Restart = always
RestartSec = 5s
StandardOutput = append:/home/ubuntu/pb/errors.log
StandardError = append:/home/ubuntu/pb/errors.log
ExecStart = /home/ubuntu/pb/pocketbase serve {YOUR_DOMAIN_OR_SUB_DOMAIN_HERE}
[Install]
WantedBy = multi-user.target
Notice the file paths and the user. Also, include your subdomain or domain. (Which by now you have pointed to the VPS I suppose).
NB: Running PocketBase with a domain/sub-domain allows it to assign SSL cert automatically and binds to 80 and 443 meaning you are able to access it without a proxy server. The people behind it are thoughtful like that. Can you imagine not needing a proxy server? Plus automated SSL?
- Reload systemctl and include the service
sudo systemctl daemon-reload
sudo systemctl enable pocketbase.service
sudo systemctl start pocketbase
- Bonus
Check the logs of PocketBase. You can also check for errors by running
cat ~/pb/errors.log
if you followed the setup above.
sudo journalctl -u pocketbase
That is it! you should now be able to access the PocketBase Admin by going to yourdomain.tld/_/
Enjoy!
Top comments (0)