Deploy to Railway

Put the starter on a public HTTPS address with the Railway template, connect your repository, add your own domain and switch on the extras.

Updated · 3 min read

The README's Deploy on Railway button creates the whole production setup with no input: Postgres, the API and a public web service, on one private network. The first deploy takes 10 to 20 minutes. Then you make yourself an admin, connect your own repository and add a domain.

Deploy the template

  1. Open the README on GitHub and click Deploy on Railway. Sign in to Railway if asked.

  2. The template creates three services: Postgres, server (the API, which runs migrations before each deploy) and web (the app behind a Caddy proxy, the only public service). It also generates the auth secret.

  3. Wait for server and web to show Active. The first build is the slowest.

  4. Open the web service's public domain (Settings → Networking) and add /health/ready. It says {"status":"ready"}.

  5. Sign up on the live site.

  6. Make yourself an admin. In Railway, open the Postgres service's Data tab and run:

    UPDATE "user" SET role = 'admin' WHERE email = 'you@example.com';
    

    Or, with the Railway CLI and psql installed, run railway connect Postgres and paste the same line.

  7. Reload, open Admin → Pages and click Install site template.

Railway bills by usage. Check their pricing before you deploy.

Deploy your own copy

The button builds the starter's own repository. To deploy your copy, and have every push redeploy, open server and web in Railway in turn, go to Settings → Source and connect your GitHub repository. Keep the root directory and the Dockerfile paths the template set: deploy/server.Dockerfile and deploy/web.Dockerfile, held in each service's RAILWAY_DOCKERFILE_PATH variable.

Keep server and Postgres private. Only web gets a public domain. The app and the API share that one HTTPS address, and sign-in cookies depend on it.

Use your own domain

  1. Add the domain to web with target port 8080, or run railway domain <domain> -s web -p 8080.
  2. Create the CNAME and _railway-verify TXT records Railway shows, at your DNS provider. On Cloudflare, set both to DNS only so Railway can issue the certificate.
  3. On server, set BETTER_AUTH_URL and APP_ORIGIN to https://<your domain> and redeploy server. Sign-in is refused from any other address.
  4. Update the Google and GitHub callback URLs if you use them.

Passkeys belong to the host in APP_ORIGIN. Ones added on the Railway domain stop working on your own domain, so move to your domain before people add passkeys.

Separate api. and mcp. hosts are optional. Add them to web the same way, set API_HOST and MCP_HOST on web and MCP_URL=https://mcp.<domain> on server, then redeploy both. The api. host sends / to the API reference; the mcp. host is the address agents connect to. See Agents and the API.

Switch on the extras

Each one is off until its variables are set on server in Railway, or in apps/server/.env locally. Each takes a redeploy or a restart.

Turn onWhat you setMore
PaymentsSTRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, STRIPE_PRICE_PRO, STRIPE_PRICE_TEAM (test mode first)Plans and billing
Account emailsLOOPS_API_KEY and the template idsEmail
Google or GitHub sign-inGOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET, or GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRETSign-in and accounts
Analytics in PostHogPOSTHOG_PROJECT_KEY and POSTHOG_HOST on server, plus VITE_POSTHOG_PROJECT_KEY and VITE_POSTHOG_HOST on webAnalytics and the audience
A public demo loginDEMO_EMAIL and DEMO_PASSWORD for an account whose role is viewerThe admin panel
Affiliate report access for scriptsAFFILIATES_READ_TOKEN, at least 32 charactersThe affiliate program

The VITE_POSTHOG_* values are compiled into the web app, so change them and rebuild web.

Until Loops is set up, password-reset and verification emails can't be delivered. Set it up before you invite real users.

In production, new passwords are checked against Have I Been Pwned, which needs outbound HTTPS from server. Set PWNED_PASSWORD_CHECK=off to skip it. Admin changes need a passkey sign-in from the last 15 minutes; set ADMIN_PASSKEY_STEP_UP=off only where admins can't use passkeys.

Check the deploy

  1. The server deploy log shows Migrations up to date, then API started.
  2. curl https://<domain>/health/ready returns {"status":"ready"}.
  3. Sign up, sign out, sign in, and create an organisation at /organisations.
  4. Without Stripe keys, the billing page says billing is off. With them, subscribe with a test card and check the webhook's delivery log in Stripe shows 200s.

Not using Railway

The same app runs anywhere with Docker Compose and Caddy. Copy deploy/.env.example to deploy/.env and set PUBLIC_HOST, POSTGRES_PASSWORD, DATABASE_URL (same password, URL-encoded) and BETTER_AUTH_SECRET (openssl rand -base64 48). Then:

docker compose --env-file deploy/.env -f deploy/compose.yaml config
docker compose --env-file deploy/.env -f deploy/compose.yaml up --build -d

Point DNS at the host and Caddy obtains the certificate for PUBLIC_HOST.

Something unclear or missing? Ask us and we'll answer, then fix the page.