How to Self-Host Supabase on Your Own Server Using Coolify: A Complete Guide for Beginners

How to Self-Host Supabase on Your Own Server Using Coolify: A Complete Guide for Beginners

How to Self-Host Supabase on Coolify: The Complete Guide

Self-hosting your backend infrastructure gives you complete control over your data and applications. If you're looking for a Firebase alternative with the freedom of self-hosting, Supabase combined with the Coolify platform offers an excellent solution. This comprehensive guide will walk you through how to self-host Supabase on Coolify, from prerequisites to advanced configurations.

What You'll Learn! In this guide, you'll discover how to deploy your own Supabase instance using Coolify, customize domains, configure email settings, secure your deployment, and troubleshoot common issues.
Table of Contents

Introduction to Self-Hosting Supabase

Supabase has emerged as a powerful open-source alternative to Firebase, providing PostgreSQL database, authentication, storage, and serverless functions. Self-hosting Supabase gives you several advantages:

  • Complete control over your data and infrastructure
  • Potential cost reduction compared to managed cloud services
  • Freedom from vendor lock-in
  • Flexibility to customize your deployment

Coolify makes self-hosting easier by providing a user-friendly platform to deploy and manage applications on your own infrastructure. It acts as a management layer over Docker, simplifying complex deployments while supporting a wide range of server options.

Prerequisites for Self-Hosting Supabase

Before starting the deployment process, ensure you have the following prerequisites in place:

Server Requirements

Requirement Specification Notes
Server Type VPS, Dedicated Server, or Local Machine Must be accessible via SSH
Operating System Linux (Ubuntu recommended) Coolify is designed for Linux-based systems
RAM Minimum 2GB More recommended for production use
Docker Version 24+ Must be installed and running
Command-line tools curl Required for installation scripts
Warning! Insufficient server resources can lead to deployment failures or performance issues. For production environments, consider using a more powerful server with at least 4GB RAM.

Coolify Installation

If you don't have Coolify installed yet, follow these steps:

  1. SSH into your server as root
  2. Run the Coolify installation script: curl -fsSL https://get.coolify.io | bash
  3. Access the Coolify dashboard by navigating to http://YOUR_SERVER_IP:8000
  4. Complete the initial setup process

Network Configuration

Ensure your server's firewall allows traffic to the following ports:

  • Port 8000 - For Coolify's web interface
  • Port 80/443 - For HTTP/HTTPS traffic to your Supabase instance
  • Additional ports used by Supabase services (if needed)

Step-by-Step Deployment of Supabase on Coolify

Now that you have the prerequisites in place, let's deploy Supabase on Coolify with these simple steps:

1. Create a New Project in Coolify

  1. Log in to your Coolify dashboard
  2. Navigate to the "Projects" tab
  3. Click the "Add" or "Create New Project" button
  4. Enter a name for your project (e.g., "Supabase")
  5. Select the appropriate environment (e.g., "Production")
  6. Click "Add" to create the project
Info!
Projects in Coolify help you organize multiple self-hosted applications and services in a logical manner.

2. Add Supabase as a Resource

  1. Within your newly created project, click "Add a new resource"
  2. Search for "Supabase" in the available services
  3. Select "Supabase" from the results

Coolify provides Supabase as a ready-to-deploy service, which abstracts away the complexity of manually configuring Docker containers.

3. Select the Target Server

For optimal performance and stability, consider deploying Supabase on a separate server from the one running Coolify itself:

  1. From the server selection dropdown, choose your target server
  2. Ideally, select a server different from where Coolify is running
Info!
To add additional servers to Coolify, navigate to the "Servers" section and provide the server's IP address and SSH credentials.

4. Configure the URL (Optional)

You can customize the initial URL for your Supabase instance:

  1. In the deployment setup, locate the URL configuration field
  2. Customize the URL prefix if desired (e.g., "db.yourdomain.com")

More advanced domain configuration can be done after the initial deployment.

5. Deploy Supabase

  1. Click the "Deploy" button to start the deployment process
  2. Coolify will pull the necessary Docker images and start the containers
  3. Monitor the deployment progress in the Coolify dashboard
  4. Wait for all services to show a "healthy" or "running" status (indicated by green icons)
Warning! The deployment process may take several minutes depending on your server's network speed and resources.

Post-Deployment Configuration and Access

After successfully deploying Supabase, you'll need to access and configure the Supabase Studio interface:

Accessing Supabase Studio

  1. In the Coolify dashboard, copy the URL provided for your Supabase resource (without any port number)
  2. Open this URL in a web browser to access the Supabase Studio login page
  3. Locate the login credentials in the Coolify interface under the resource's "General Settings" or "Credentials" section
  4. Look for fields named "Supabase Dashboard User" and "Supabase Dashboard Password"
  5. Use these credentials to log in to Supabase Studio
Important Security Note! Change the default credentials immediately after your first login to secure your Supabase instance.

Exploring Supabase Studio

Once logged in, you'll have access to a comprehensive suite of tools for managing your Supabase project:

  • SQL Editor - For executing database queries
  • Table Editor - For managing database schema
  • Authentication - For configuring user sign-up and login methods
  • Storage - For managing file uploads
  • Edge Functions - For serverless backend logic
  • API Documentation - For integrating with client applications

Explore the Supabase documentation to learn how to effectively use these features for your application.

Advanced Configuration

To fully customize your self-hosted Supabase instance, you may want to implement some advanced configurations:

Setting Up a Custom Domain

Using a custom domain improves branding and makes your Supabase instance more accessible:

  1. Navigate to the settings of your Supabase resource in Coolify
  2. Find the Kong API gateway settings and edit them to add your custom domain
  3. Create a DNS record with your domain provider that points to your server's IP address:
    • Create an "A" record pointing your domain or subdomain to the server's IP address
    • Or create a "CNAME" record if appropriate for your setup
  4. Update environment variables in Coolify:
    • Set API_EXTERNAL_URL to your custom domain (e.g., https://supabase.yourdomain.com)
    • Update ADDITIONAL_REDIRECT_URLS to include your custom domain

Configuring Email Services

To enable user registration, password resets, and email confirmations, configure an SMTP server:

  1. In the Coolify interface, go to your Supabase resource's environment variables
  2. Configure the following SMTP variables:
    • SMTP_HOST - Your SMTP server address
    • SMTP_PORT - Typically 465 for SMTPS or 587 for STARTTLS
    • SMTP_USER - Email address or username for the SMTP server
    • SMTP_PASS - Password for the SMTP account
    • SMTP_ADMIN_EMAIL - The email address from which Supabase will send emails
    • SMTP_SENDER_NAME - The name that will appear in the "From" field
  3. Optional: Customize email templates by editing the HTML files in the persistent storage associated with the Supabase service

Managing Environment Variables

Fine-tune your Supabase instance by configuring important environment variables:

Variable Purpose Notes
JWT_SECRET Used for signing and verifying JWTs Critical for authentication security
ANON_KEY Public API key for client-side access Has restricted permissions
SERVICE_ROLE_KEY Administrative API key Use with extreme caution, server-side only
DISABLE_SIGNUP Controls whether new users can sign up Set to "true" to prevent new sign-ups
ENABLE_EMAIL_SIGNUP Controls email-based sign-up Set to "false" to disable email sign-up

Coolify provides both standard and developer views for managing these variables. The developer view offers more granular control through raw editing of configuration files.

Troubleshooting Common Issues

Even with Coolify's streamlined process, you might encounter issues when self-hosting Supabase. Here are solutions to common problems:

Supabase Build Error with MinIO x86 v2 or minio/mc Unhealthy Exit

If you're encountering a Supabase build error related to MinIO x86 v2 or see errors like:

Error! CreateBucket error or minio/mc exit with unhealthy status

A fix suggested by Theo in Tech involves switching to the latest v1-compatible MinIO images. These versions are more stable on x86 architectures. Use the following Docker images (as of 04/10/2024):

  1. MinIO Server: minio/minio:RELEASE.2024-10-02T17-50-41Z-cpuv1
  2. MinIO Client (mc): minio/mc:RELEASE.2024-10-02T08-27-28Z-cpuv1
image_alt

Source:
https://github.com/coollabsio/coolify/issues/2360

Replace your existing image references in docker-compose.yml with the above versions to resolve the issue.

Analytics Container Failing

If the Supabase Analytics container fails to start or crashes repeatedly:

  1. Check the container logs in Coolify for specific error messages
  2. Consider temporarily reverting to an older, stable version of the Docker Compose file
  3. If you've made the PostgreSQL database publicly accessible (not recommended without security measures), you could try connecting directly to the database and manually creating the necessary _supabase database and schemas

Database Accessibility Issues

If you need to make the Supabase database publicly accessible, Coolify has a known bug with a specific workaround:

  1. In Coolify, set the "Supabase Db" option to "public"
  2. Go to the "General" tab and click "Edit Compose File"
  3. In the docker-compose.yml file, locate the supabase-db service
  4. Under the ports section, add: - ${POSTGRES_PORT:-5432}:${POSTGRES_PORT:-5432}
  5. Save the file and restart the Supabase service
  6. If changing the default PostgreSQL port, also update the POSTGRES_PORT environment variable
Warning! Making your database publicly accessible poses security risks. Implement proper security measures if you choose this option.

Deployment Failures

If your Supabase deployment fails in Coolify:

  1. Examine the deployment logs in Coolify for specific error messages
  2. Verify that your server meets the minimum resource requirements
  3. Check that Docker is running correctly (SSH into the server and run docker ps)
  4. Ensure proper network connectivity between the Coolify server, target server, and external resources

Security Considerations

Securing your self-hosted Supabase instance is crucial to protect sensitive data:

Changing Default Credentials

Immediately after deployment, change the default credentials:

  1. Update the Supabase dashboard username and password in the Supabase Studio interface or through Coolify's environment variables
  2. Look for variables named DASHBOARD_USERNAME and DASHBOARD_PASSWORD

Managing API Keys

Supabase uses two main API keys that need proper handling:

  • anon key - For public read access, should be handled carefully
  • service_role key - For administrative access, must be kept highly secure and used only in server-side environments

Consider using a dedicated secrets manager for storing these keys securely.

Network Security

  1. Configure firewall rules to restrict access to only necessary ports
  2. Use HTTPS to encrypt communications (Coolify can automatically set up Let's Encrypt certificates)
  3. If exposing the PostgreSQL database directly (not recommended), implement strong authentication and IP restrictions

Limitations of Self-Hosted Supabase

While self-hosting offers many benefits, be aware of these potential limitations compared to the fully managed Supabase platform:

  • Some advanced features may not be available in the self-hosted version
  • Edge Functions, detailed logging, and comprehensive reporting tools might be limited
  • Manual configuration may be required for certain tasks that are automated in the cloud version
  • Managing multiple isolated Supabase projects might require separate deployments
  • The Supabase CLI might have reduced functionality with self-hosted instances

Evaluate your specific feature requirements before choosing self-hosting over the managed cloud platform.

Conclusion

Self-hosting Supabase on Coolify provides a powerful, flexible backend solution with complete control over your data and infrastructure. By following this comprehensive guide, you can successfully deploy, configure, and secure your own Supabase instance.

Coolify's one-click deployment significantly simplifies what would otherwise be a complex setup process, making self-hosting accessible even to those without extensive DevOps experience. The post-deployment configurations allow you to customize your instance to meet your specific needs.

While self-hosting requires more management than using the fully managed Supabase platform, the benefits of control, potential cost savings, and avoiding vendor lock-in make it an attractive option for many developers and organizations.

Resources!

Post a Comment