Deploy Supabase Next.js

Self-hosted Supabase backend for Next.js apps

Deploy Supabase Next.js

Just deployed

/var/lib/postgresql/data

/var/lib/storage

Just deployed

/app/snippets

Deploy and Host Supabase Next.js (Open-Source Firebase Alternative) on Railway

This template deploys Supabase on Railway as the backend for a Next.js App Router app.

About Hosting Supabase Next.js on Railway (self hosted Supabase template)

This template runs the full self-hosted Supabase stack: Postgres, Auth, PostgREST, Realtime, Storage, Edge Functions, and Studio behind a single gateway.

Why Deploy Supabase Next.js on Railway (Railway Free Trial)

Railway's $5 trial lets you run this nine-service stack without commitment, and self-hosting avoids Firebase's proprietary NoSQL lock-in.

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Supabase Next.js on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Railway vs Other Hosting Providers and VPS for Supabase Next.js self hosting

Railway runs the nine-service Supabase stack for you, while a plain VPS leaves you to assemble the same pieces.

ProviderWhat You Get with RailwayWhat You Get with the Other Provider
DigitalOceanNine preconfigured services, auto-generated secrets, gateway logs with anon keyManual Docker Compose setup where you generate the JWT secret and API keys yourself
AWSOne-click template with Postgres volume, Envoy gateway, and Studio on a free trialEC2 or ECS with you wiring GoTrue, PostgREST, Realtime, and storage yourself
HetznerPostgres and file storage on Railway volumes, plus a public URL and auth redirect variablesBare server where you install every dependency and handle SSL, DNS, and backups

That prewired setup is why Railway's trial often feels quicker than building the same stack on a bare VPS.

Common Use Cases for hosted Supabase Next.js

SaaS app with login. Use createServerClient in a server component to read the session, then render a dashboard from Postgres via createBrowserClient in client components. Row Level Security keeps each tenant's rows private.

Realtime collaborative editor. Subscribe to a Supabase channel from a client component and broadcast presence or updates through the gateway's /realtime/v1 route.

File uploads with storage. Call /storage/v1 from a server action, enforce the 50 MB limit, and store the returned path in a table protected by RLS.

Admin-only server actions. Keep the service_role key in server-side env only, never in NEXT_PUBLIC, and use it in route handlers to bypass RLS for trusted operations like deleting abuse reports.

Auth redirects for production. Set GOTRUE_SITE_URL to your Next.js app URL and add https://your-app/auth/callback to GOTRUE_URI_ALLOW_LIST, then refresh the auth cookie in middleware.

Dependencies for Supabase Docker hosted on Railway

This template runs nine services. The anon and service_role keys derive from JWT_SECRET. The supabase gateway is Envoy v1.39.1 on port 8000 and routes to PostgREST, Auth, Storage, Edge Functions, Realtime, postgres-meta, and Studio.

Deployment Dependencies for Managed Supabase Service (Postgres Backend)

Service images: db supabase/postgres 17.6.1.136, auth supabase/gotrue v2.196.0, rest postgrest v14.17, realtime supabase/realtime v2.134.10, storage supabase/storage-api v1.74.0, meta postgres-meta v0.99.0, functions supabase/edge-runtime v1.76.2, studio supabase/studio 2026.09.07.

Implementation Details for Supabase (Using official Supabase docker images)

Email signup and autoconfirm are on by default because no SMTP is set; configure GOTRUE_SMTP_HOST, GOTRUE_SMTP_USER, and GOTRUE_SMTP_PASS before real users.

How does Supabase compare against other backend platforms

Supabase vs Firebase (Firebase Alternative)

  • Data model: Supabase is Postgres with relational tables, joins, and SQL migrations. Firebase is NoSQL Firestore, which is fine for denormalized reads but gets painful with complex queries or reporting.

  • Lock-in: You can self-host Supabase, and the client libraries and SQL are portable. Firebase is proprietary and ties your backend to Google's cloud; moving off means a rewrite.

  • Firebase wins on: Zero-config hosting, mature client SDKs, and built-in analytics integration. If you never need SQL and want the least setup, Firebase is still easier.

Supabase vs Appwrite (Appwrite Alternative)

  • Database: Supabase gives you full Postgres. Appwrite is MariaDB under the hood, but you mostly interact through its API and document-like collections, so you lose direct SQL power.

  • Auth: Both have email/password, OAuth, and session management. Appwrite bundles more user management UI out of the box; Supabase's Auth is solid but you often wire your own UI.

  • Appwrite wins on: Simpler self-host setup for smaller apps and a more opinionated dashboard for non-SQL developers.

Supabase vs PocketBase (PocketBase Alternative)

  • Scale: Supabase runs on Postgres and supports many concurrent users and connections. PocketBase is a single Go binary using SQLite, so it's meant for small or single-server apps.

  • Realtime: Supabase Realtime is built in and scales with Postgres. PocketBase has realtime subscriptions, but they're local to that one binary.

  • PocketBase wins on: Operational simplicity. One binary, one file, near-zero config. For a side project with a few hundred users, PocketBase is less work.

Supabase vs Neon (Neon Alternative)

  • Scope: Supabase is a full backend: Postgres plus auth, storage, realtime, and edge functions. Neon is serverless Postgres only, so you bring your own auth and API layer.

  • Features: Supabase includes auto-generated REST and GraphQL APIs, RLS helpers, and the Studio dashboard. Neon is excellent at Postgres but expects you to build the app layer.

  • Neon wins on: Pure Postgres developer experience, instant branching, and serverless scale-to-zero. If you only need a database and already have a backend, Neon can be cleaner.

How to use Supabase Next.js (the OSS Postgres backend)?

  1. Install @supabase/supabase-js and @supabase/ssr.
  2. Set NEXT_PUBLIC_SUPABASE_URL to the supabase service gateway URL.
  3. Set NEXT_PUBLIC_SUPABASE_ANON_KEY to the anon key printed in gateway logs.
  4. Use createBrowserClient in client components.
  5. Use createServerClient with Next.js cookies in server components, route handlers, and server actions.
  6. Add middleware that calls supabase.auth.getUser and refreshes the session cookie.
  7. Set GOTRUE_SITE_URL to your app URL and add https://your-app/auth/callback to GOTRUE_URI_ALLOW_LIST.
  8. Turn on Row Level Security for every table the browser can reach, then start building.

How to self host Supabase on other VPS Services (Supabase self hosting guide)

Clone the Repository

git clone --depth 1 https://github.com/supabase/supabase
cd supabase/docker

The docker folder holds the upstream docker-compose.yml for the full stack.

Install Dependencies

docker compose pull

This also pulls the Postgres image, so no separate database install is needed.

Configure Environment Variables

Copy .env.example to .env and change every secret.

Start the Supabase Application

docker compose up -d

Upstream, the anon and service_role keys live in .env, so generate them from your JWT secret before first start. Log into Studio with your dashboard credentials, then use ANON_KEY from .env for NEXT_PUBLIC_SUPABASE_ANON_KEY. Railway handles the networking, volumes, and secret generation so you skip this manual compose setup.

Official Pricing of Supabase (Supabase pricing)

Supabase Cloud has a Free tier with two projects, a 500 MB database, and pausing after one week of inactivity. Pro starts at $25 per month per organization and includes $10 in compute credits.

Supabase cloud vs self hosted comparison (Pricing, features, costs, and more)

Cloud handles scaling, backups, and branching but charges per project and org.

Monthly cost of self hosting Supabase on Railway

Expect roughly 20-40 USD/mo for the nine small services at light use, more as Postgres grows. The Railway 5 USD trial covers a first test.

System Requirements for Hosting Supabase on a VPS

Upstream suggests at least 4 GB RAM for the full stack.

Frequently Asked Questions (FAQs)

Where do I find the Supabase URL and anon key for Next.js?

Open the supabase service deploy logs. The gateway prints the public URL and anon key; copy them into NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY.

Do I need to configure email delivery before testing signups?

No. Email autoconfirm is on because no SMTP is set, so signup links or OTPs are not actually sent. For real users, set GOTRUE_SMTP_HOST, GOTRUE_SMTP_USER, and GOTRUE_SMTP_PASS, then turn autoconfirm off.

How do I use Supabase in App Router server components?

Install @supabase/supabase-js and @supabase/ssr. Use createServerClient with the Next.js cookies API in server components, route handlers, and server actions; middleware should refresh the auth session cookie.

Can I expose the service_role key in NEXT_PUBLIC variables?

No. Keep service_role only in server-side environment. The anon key is safe for browser use, but the service_role key bypasses RLS and must never reach the client.

What do I set for GOTRUE_SITE_URL and callback URLs?

Set GOTRUE_SITE_URL to your Next.js app URL. Add the app's /auth/callback or other redirect URLs to GOTRUE_URI_ALLOW_LIST as comma-separated values; API_EXTERNAL_URL stays the gateway URL.

Is Row Level Security required?

Yes. Turn on RLS for every table the browser can reach. Without it, the anon key can read or write data regardless of auth policies.


Template Content

More templates in this category

View Template
NEW
RustFS | (Just Updated) S3 Object Store, Public URL and Keys Set
S3-compatible object store, keys and public URL preset, volume kept

SuperSlowSloth
0
View Template
TimescaleDB
A PostgreSQL-based time-series database for analytics on Railway.

Rakit
1
View Template
Garage S3 Storage
Ultra-light S3 server: fast, open-source, plug-and-play.

PROJETOS
8