Deploy to Railway
Deploy a Tyravel app to Railway using a Dockerfile or Nixpacks with managed Postgres.
Prerequisites
- Railway account and CLI (optional)
- Tyravel app with Postgres:
tyravel new my-app --db=postgres @tyravel/database-pginstalled
Option A — Dockerfile (recommended)
- Copy deploy files from
examples/hello-world/deploy/ - Connect your GitHub repo in Railway
- Railway detects
Dockerfileand builds automatically
Service variables
Set in the Railway dashboard (Variables tab):
| Variable | Value |
|---|---|
NODE_ENV | production |
APP_ENV | production |
APP_DEBUG | false |
APP_URL | https://${{RAILWAY_PUBLIC_DOMAIN}} |
TYRAVEL_HOST | 0.0.0.0 |
TYRAVEL_PORT | ${{PORT}} |
DB_CONNECTION | postgres |
DB_HOST | ${{Postgres.PGHOST}} |
DB_PORT | ${{Postgres.PGPORT}} |
DB_DATABASE | ${{Postgres.PGDATABASE}} |
DB_USERNAME | ${{Postgres.PGUSER}} |
DB_PASSWORD | ${{Postgres.PGPASSWORD}} |
QUEUE_CONNECTION | database |
Add a Postgres plugin; Railway exposes PG* variables you reference above.
Pre-deploy command
In Settings → Deploy → Pre-deploy command:
bash
npx tyravel migrate \
&& npx tyravel route:cache \
&& npx tyravel view:cacheStart command
Leave empty to use Dockerfile CMD, or set explicitly:
bash
./deploy/docker-entrypoint.shOption B — railway.toml
toml
[build]
builder = "DOCKERFILE"
dockerfilePath = "Dockerfile"
[deploy]
preDeployCommand = "npx tyravel migrate"
startCommand = "./deploy/docker-entrypoint.sh"
healthcheckPath = "/health/ready"
healthcheckTimeout = 30
restartPolicyType = "ON_FAILURE"Queue worker (second service)
- Duplicate the service in Railway
- Name it
worker - Start command:
bash
npx tyravel queue:work- Share the same Postgres variables; disable public networking on the worker.
Redis + broadcasting (optional)
- Add Railway Redis plugin (or Upstash Redis)
- Set
REDIS_URL/REDIS_HOSTvariables - Scaffold with
--redisandBROADCAST_CONNECTION=websocket - Add
@tyravel/broadcasting-websocketprovider insrc/main.ts
Custom domain
- Settings → Networking → Custom domain
- Update
APP_URLtohttps://your-domain.com - Redeploy so signed URLs and mail links resolve correctly
Local parity
bash
railway link
railway run npx tyravel startUses linked service variables against your local process.
Troubleshooting
| Symptom | Fix |
|---|---|
| Port binding error | Set TYRAVEL_PORT to Railway's PORT variable — Railway injects PORT at runtime |
| View cache miss | Add view:cache to pre-deploy command |
| DB connection refused | Confirm Postgres plugin is linked to the same service |
| Worker not processing | Deploy worker service; check jobs table |
Next
- Deployment overview — shared checklist
- Tutorial 4 — production task list