Self-hosting Supabase gives you complete control over your backend infrastructure, database, authentication services, storage, and APIs. In this tutorial, you’ll learn how to deploy Supabase on Ubuntu 24.04 using the official installation method, secure the deployment with HTTPS, verify service health, create backups, and safely perform updates.
This guide follows the official self-hosted installation workflow and includes important security and recovery recommendations.
Prerequisites
Before starting:
- Ubuntu 24.04 server
- A domain name that points to your server
- Root or sudo access
- Sufficient CPU, RAM, and storage resources based on Supabase’s current requirements
- Internet connectivity for downloading packages and container images
Step 1: Verify Ubuntu, Server Resources, DNS, and Open Ports
Before installing Supabase, confirm that the server meets the expected requirements and that your domain is correctly configured.
a) Check Ubuntu Version and Architecture
Run the following commands:
cat /etc/os-release
uname -m

These commands display your Ubuntu version and system architecture.
b) Check Available CPU, Memory, and Disk Space
nproc
free -h
df -h /
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINTS

These commands show:
- CPU core count
- Available RAM
- Filesystem usage
- Attached storage devices
Ensure your server meets Supabase’s documented resource requirements.
c) Verify DNS Records
Set your domain name:
export SUPABASE_DOMAIN=supabase.example.com
Check IPv4 and IPv6 records:
dig +short A "$SUPABASE_DOMAIN"
dig +short AAAA "$SUPABASE_DOMAIN"

The returned IP address should match your server.
Important: Only publish an AAAA record if IPv6 traffic is properly configured and secured.
d) Check Existing Network Listeners
sudo ss -tulpn

This displays services currently listening on network ports. Ports 80 and 443 must be available for the HTTPS reverse proxy.
Step 2: Install Required Packages and Review the Official Setup Script
Install the tools used during deployment.
a) Install Dependencies
sudo apt update
sudo apt install -y ca-certificates curl git openssl jq dnsutils

These utilities are required for downloading files, verifying DNS, generating certificates, and processing configuration data.
b) Download the Official Setup Script
Instead of executing a remote script directly, download it first for review.
curl -fsSL https://supabase.link/setup.sh -o setup.sh

c) Inspect the Script Contents
sed -n '1,220p' setup.sh
Review the script before execution so you understand what will be installed and configured.
d) Verify the Download
test -s setup.sh && echo 'Supabase setup script downloaded'
This confirms the file exists and is not empty.
Best Practice: Never execute an unreviewed remote shell script in a production environment.
Step 3: Run the Supabase Installer
Launch the installation process.
sh setup.sh

During installation, enter your deployment URLs when prompted.
Example configuration:
- SUPABASE_PUBLIC_URL=https://supabase.example.com
- API_EXTERNAL_URL=https://supabase.example.com/auth/v1
- PROXY_DOMAIN=supabase.example.com
- SITE_URL=https://app.example.com
Important: SITE_URL refers to your application URL, not the Supabase server URL.
Review Generated Project Files
Enter the created project directory:
cd supabase-project
ls -la

Check the installed version:
cat .supabase-version

Step 4: Review Generated Secrets and Configuration
After installation, inspect the generated credentials.
a) View Generated Secrets
sh run.sh secrets

Only do this in a secure administrator session.
b) Open the Environment File
nano .env

Verify values such as:
- SUPABASE_PUBLIC_URL=https://supabase.example.com
- API_EXTERNAL_URL=https://supabase.example.com/auth/v1
- SITE_URL=https://app.example.com
- PROXY_DOMAIN=supabase.example.com
c) Verify Credentials
Confirm that:
- Dashboard password is not using a default value
- API keys were generated successfully
- URLs are correct
Search for Unchanged Placeholders
grep -nE 'CHANGE_ME|your-super-secret|your-tenant-id|your-domain' .env || true
Review any matches and replace incomplete values.
Security Warning: Never expose service-role keys or server-side secrets in frontend code, public repositories, screenshots, logs, or support tickets.
Step 5: Secure Environment Files and Configure the Firewall
a) Protect the .env File
Restrict access permissions:
chmod 600 .env
stat -c '%a %n' .env

b) Review Firewall Status
sudo ufw status numbered

c) Allow HTTP and HTTPS Traffic
If UFW is already enabled:
sudo ufw allow 80/tcp comment 'Supabase HTTP/ACME'
sudo ufw allow 443/tcp comment 'Supabase HTTPS'
sudo ufw status numbered
These rules allow web traffic and TLS certificate validation.
Warning: Do not enable UFW remotely without first confirming SSH access rules, as you could lock yourself out of the server.
d) Keep Internal Services Private
Avoid exposing:
- PostgreSQL
- Supavisor
- Studio backend services
- Internal API services
unless your architecture explicitly requires it.
Step 6: Start Supabase and Verify Service Health
a) Start the Stack
cd supabase-project
sh run.sh start

The startup process launches services and waits for health checks.
b) Check Container Status
docker compose ps

All required services should report healthy status.
c) Run Diagnostics
If any service fails health checks:
sh tests/test-container-logs.sh

d) View Individual Service Logs
Example:
sh run.sh logs storage

This displays logs for the Storage service.
Step 7: Enable HTTPS with the Supabase Caddy Configuration
Supabase’s recommended production deployment uses Caddy as the HTTPS reverse proxy.
a) Reconfirm DNS
SUPABASE_DOMAIN=supabase.example.com
dig +short A "$SUPABASE_DOMAIN"
Verify the domain resolves to your server.
b) Enable the Caddy Configuration
cd supabase-project
sh run.sh config add caddy
sh run.sh start
Caddy will:
- Obtain TLS certificates
- Handle HTTPS traffic
- Support WebSocket connections required by Realtime
- Inspect Caddy Logs
If certificates fail to issue:
docker logs supabase-caddy --tail=100
Step 8: Verify HTTPS, Authentication, and Studio Access
a) Test the Auth Endpoint
curl -I https://supabase.example.com/auth/v1/
A 401 Unauthorized response indicates requests are successfully reaching the authentication service.
b) Access Supabase Studio
Open:
https://supabase.example.com

Log in using the generated dashboard credentials.
c) Test the REST API Gateway
curl -I https://supabase.example.com/rest/v1/
The goal is simply to verify the gateway responds through HTTPS.
d) Verify Services in Studio
Confirm the following sections load correctly:
- Database
- Authentication
- Storage
- Realtime
Step 9: Perform an End-to-End Database Test
Use the SQL Editor in Supabase Studio.
a) Create a Test Table
create table if not exists public.raff_supabase_test (
id bigint generated by default as identity primary key,
note text not null,
created_at timestamptz not null default now()
);

b) Insert a Test Record
insert into public.raff_supabase_test (note)
values ('self-hosted Supabase verification');
c) Query the Data
select * from public.raff_supabase_test;
This verifies that the database is working correctly.

d) Remove the Test Table
drop table if exists public.raff_supabase_test;

Cleaning up test data helps keep the environment tidy.
Step 10: Understand PostgreSQL and Supavisor Exposure
Supabase uses Supavisor as the default connection pooler.
Common ports include:
- 5432 Session mode
- 6543 Transaction mode
These ports should not automatically be exposed to the public internet.
Inspect Current Port Mappings
cd supabase-project
docker compose config | grep -nE '5432|6543|8000' | head -n 40
Review how services are exposed before opening firewall rules.
Best Practice: For internet-facing applications, use the HTTPS API gateway whenever possible instead of exposing PostgreSQL directly.
Step 11: Create Comprehensive Backups
Supabase’s update process does not back up PostgreSQL data or Storage files. You should build your own backup strategy.
a) Create a Backup Directory
cd supabase-project
mkdir -p backups/manual
chmod 700 backups/manual
STAMP="$(date -u +%Y%m%d-%H%M%S)"

b) Back Up Database Roles
docker compose exec -T db \
pg_dumpall -U postgres --roles-only \
| gzip > "backups/manual/roles-${STAMP}.sql.gz"
c) Back Up the Database
docker compose exec -T db \
pg_dump -U postgres -d postgres -Fc \
> "backups/manual/postgres-${STAMP}.dump"

d) Back Up Storage Data
tar -czf "backups/manual/storage-${STAMP}.tar.gz" \
volumes/storage
e) Back Up Configuration Files
tar -czf "backups/manual/config-${STAMP}.tar.gz" \
.env .supabase-version docker-compose.yml run.sh update.sh volumes/proxy 2>/dev/null || \
tar -czf "backups/manual/config-${STAMP}.tar.gz" \
.env .supabase-version docker-compose.yml run.sh volumes/proxy
f) Secure Backup Files
chmod 600 backups/manual/*

g) Validate Backup Integrity
gzip -t "backups/manual/roles-${STAMP}.sql.gz"
pg_restore -l "backups/manual/postgres-${STAMP}.dump" | head
tar -tzf "backups/manual/storage-${STAMP}.tar.gz" | head
tar -tzf "backups/manual/config-${STAMP}.tar.gz" | head

Important: Store backups off-server and keep them in a separate failure domain.
Step 12: Test Your Restore Process
Backups are only useful if they can be restored successfully.
Use an isolated test VM rather than restoring over production.
a) Start the Database Service
cd supabase-project
docker compose up -d db

b) Restore Roles
gunzip -c /backup/roles-YYYYMMDD-HHMMSS.sql.gz \
| docker compose exec -T db psql -U postgres -d postgres
c) Restore the Database
docker compose exec -T db \
pg_restore -U postgres -d postgres --clean --if-exists \
< /backup/postgres-YYYYMMDD-HHMMSS.dump
d) Restore Storage Files
tar -xzf /backup/storage-YYYYMMDD-HHMMSS.tar.gz -C .
e) Start Supabase
sh run.sh start

Verify:
- Studio access
- Database records
- Authentication data
- Storage objects
Recommendation: Disable external integrations such as SMTP, OAuth callbacks, and webhooks during recovery testing.
Step 13: Update Supabase Safely
Always perform full backups before updating.
a) Check the Current Version
cd supabase-project
cat .supabase-version

b) Preview the Update
sh update.sh --dry-run

Review:
- Version changes
- New environment variables
- Configuration updates
- Breaking changes
c) Apply the Update
sh update.sh

d) Pull Updated Images
sh run.sh pull

e) Recreate Services
sh run.sh recreate

f) Verify the Upgrade
cat .supabase-version
docker compose ps

All required services should return to a healthy state.
Step 14: Perform a Final Security and Health Audit
Run a final verification before declaring the deployment production-ready.
a) Check Installed Version and Services
cd supabase-project
cat .supabase-version
docker compose ps
b) Verify Public HTTPS Endpoints
curl -I https://supabase.example.com/auth/v1/
curl -I https://supabase.example.com/rest/v1/
c) Review Active Ports
sudo ss -tulpn

d) Review Firewall Rules
sudo ufw status numbered

Final Checklist
Confirm the following:
- Ubuntu has sufficient resources
- .supabase-version exists and contains a valid version
- Services are running from a tested Supabase release snapshot
- .env permissions are set to 600
- Dashboard credentials are not default values
- Secret and service-role keys are not exposed
- HTTPS terminates at the intended reverse proxy
- Realtime traffic works through WebSocket support
- Internal database ports are not unintentionally public
- PostgreSQL and Storage backups exist
- Configuration files are backed up separately
- Restore testing has been completed
- New backups are taken after upgrades
Conclusion
You have successfully deployed a self-hosted Supabase environment on Ubuntu 24.04 using the official installation workflow. Along the way, you verified system requirements, configured DNS, enabled HTTPS with Caddy, secured sensitive configuration files, tested database functionality, created reliable backup procedures, and learned how to safely update and restore your environment.
Following these operational and security best practices will help ensure your Supabase deployment remains stable, recoverable, and production-ready over time.




