How to Self-Host Supabase on a VPS (Complete Guide)
Supabase is an open-source alternative to Firebase that provides a powerful backend-as-a-service platform. Hosting it on a VPS can give you full control over your data and configurations. In this guide, we will walk you through the process of self-hosting Supabase on a VPS, using Docker for easy deployment.
Prerequisites
Before getting started, ensure that you have the following:
- A VPS (with at least 2 GB RAM and 1 CPU) from a provider like DigitalOcean or Hetzner.
- Basic knowledge of Docker and command-line interface (CLI).
- An SSH client to access your VPS.
| Provider | Starting Price | Recommended Specs |
|---|---|---|
| Contabo VPS | 5.99 EUR/mo | 2 GB RAM, 1 CPU |
| Hetzner Cloud | 4.15 EUR/mo | 2 GB RAM, 1 CPU |
| DigitalOcean | 6 USD/mo | 2 GB RAM, 1 CPU |
| Vultr | 6 USD/mo | 1 GB RAM, 1 CPU |
| Linode (Akamai) | 5 USD/mo | 2 GB RAM, 1 CPU |
You can compare more VPS options at our full VPS comparison.
Step 1: Set Up Your VPS
First, you need to set up your VPS. This typically involves:
-
Choosing an Operating System: We recommend Ubuntu 20.04 LTS for compatibility with Docker.
-
Accessing Your VPS: Use SSH to connect to your server:
ssh username@your-vps-ip -
Updating Your System: Ensure your packages are up-to-date:
sudo apt update sudo apt upgrade -y
Step 2: Install Docker
To run Supabase, you need Docker installed on your VPS. Follow these commands:
-
Install dependencies for Docker:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y -
Add Dockerโs official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - -
Set up the stable repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" -
Install Docker:
sudo apt update sudo apt install docker-ce -y -
Start and enable Docker:
sudo systemctl start docker sudo systemctl enable docker -
Verify the installation:
docker --version
Step 3: Pull and Run Supabase Docker Images
Now that Docker is set up, you can pull the Supabase Docker images.
-
Create a directory for your Supabase project:
mkdir supabase && cd supabase -
Create a Docker Compose file:
Create a
docker-compose.ymlfile with the following content:version: '3.8' services: db: image: supabase/postgres environment: POSTGRES_PASSWORD: your_password POSTGRES_USER: your_user POSTGRES_DB: your_db ports: - "5432:5432" auth: image: supabase/gotrue ports: - "9999:9999" realtime: image: supabase/realtime ports: - "4000:4000" studio: image: supabase/studio ports: - "3000:3000"Replace
your_password,your_user, andyour_dbwith your desired values. -
Start the Supabase services:
Run the following command in the same directory as your
docker-compose.yml:docker-compose up -d -
Check the running services:
You can check the logs using:
docker-compose logs
Step 4: Access Supabase Studio
Once your services are running, you can access Supabase Studio by navigating to http://your-vps-ip:3000 in your browser. From here, you can manage your database, authentication, and more.
FAQs
Q1: What are the benefits of self-hosting Supabase on a VPS?
Self-hosting Supabase on a VPS allows for greater control, enhanced security, and customized configurations. You manage your hardware and software, ensuring you adhere to your specific compliance needs. Additionally, it can be more cost-effective in the long run, especially if you expect significant usage, as you can avoid vendor lock-in and maintain ownership of your data.
Q2: Can I scale my Supabase instance if I need more resources?
Yes, you can scale your Supabase instance based on your needs. This can involve upgrading your VPS to a larger plan that provides greater CPU and RAM resources or optimizing your Docker configurations. Both strategies are feasible and can be executed without significant downtime, ensuring your applications remain available while you adjust your infrastructure.
Q3: What are the common issues faced when self-hosting Supabase?
Common issues include configuration mistakes, insufficient resources on the VPS, and network connectivity problems. Ensure your Docker containers are properly configured and that your VPS meets the necessary specifications. Additionally, consult the Supabase community on r/selfhosted for troubleshooting tips and best practices in self-hosting applications for advice and solutions.
By following this guide, you can successfully self-host Supabase on a VPS, allowing you to leverage a robust backend solution without compromising on control and privacy.