# Engine on Railway

URL: https://lyeve.com/docs/deploy/engine-railway/

Railway runs the engine image as a service built from a Docker image. One service can publish
both engine ports, each on its own domain. New accounts get trial credits, and after that a
service is billed by usage. A deployed service keeps running rather than sleeping, so check
Railway's current pricing before you leave it unattended.

:::tip[Best for]
- **Both APIs public from one service**, each on its own domain.
- **An engine that stays warm**, with a Railway volume for the signing key.
:::

## Before you start

- A Railway account and a project.
- A database. A Railway Postgres service in the same project works, or
  [Supabase](https://lyeve.com/docs/deploy/database-supabase/) or [Neon](https://lyeve.com/docs/deploy/database-neon/).

## Deploy

1. Add a service to the project from the Docker image
   `ghcr.io/lyeve-labs/lyeve-core:latest`. Pin a release tag in production. See
   [Docker images](https://lyeve.com/docs/deploy/docker/#images-and-tags).
2. In the service's networking settings, give one public domain to port `3001` (the Admin API)
   and one to port `3002` (the Content API).
3. Add a volume mounted at `/var/lib/lyeve`, so the signing key survives a redeploy. The engine
   runs as uid `65532`, and Railway documents that an image running as a non-root user cannot
   write to an attached volume unless the service sets `RAILWAY_RUN_UID=0`, which runs the
   container as root. Set it, or the engine cannot write the key. In production the engine
   refuses to start when it cannot write the key.

Without the volume, every redeploy creates a new key and every token issued before it stops
working. The volume keeps the key, not the sessions: refresh tokens live in the engine's memory
unless `CACHE_DRIVER=redis` and `REDIS_URL` point at a Redis, so a redeploy still signs everyone out once their access
token expires, 15 minutes by default.

## Secrets

Set these in the service's variables:

```text
DATABASE_URL=postgres://<user>:<password>@<host>:5432/<dbname>?sslmode=require
JWT_SECRET=<openssl rand -hex 32>
ENCRYPTION_KEY=<a different openssl rand -hex 32>
LYEVE_AUDIT_HMAC_KEY=<a third openssl rand -hex 32>
RATE_LIMIT_RPS=100
SECURE_COOKIE=true
CORS_ORIGINS=https://your-app.example.com
RAILWAY_RUN_UID=0
```

Production refuses to start without these values.
[Configuration](https://lyeve.com/docs/reference/configuration/#what-production-refuses) lists every check.

## Database

For a Railway Postgres service, use the internal connection string Railway generates, which
stays on Railway's network. Use the public one only when something outside Railway reaches the
database. Production refuses the database user `postgres`, so create a dedicated user for the
engine. [Supported databases](https://lyeve.com/docs/deploy/#supported-databases) lists the URL forms.

## Health checks

Set the service's health check path to `/readyz`. Both listeners serve `/healthz`, `/readyz`
and `/startup` without authentication. Do not use `/api/admin/health` or `/api/v1/health`:
they need authentication, so a check gets `401` and marks a healthy service down.
[Health endpoints](https://lyeve.com/docs/deploy/docker/#health-endpoints) says what each one checks.

## Verify

```bash
curl https://<content-api-domain>/.well-known/jwks.json
curl https://<admin-api-domain>/api/admin/setup
```

The JWKS document is on the domain for port 3002, and the setup route on the domain for port
3001. A new install answers `{"setup_required":true,"token_source":"log"}`. The setup token is
the one-time `setup_token` the engine writes to its standard error, or `LYEVE_SETUP_TOKEN`
when you set it. The service's logs show standard error, so search them for `setup_token`. The
[quickstart](https://lyeve.com/docs/getting-started/quickstart/) continues from step 2.

## LyEve Console

This page sets up the engine alone. The console runs as its own service, from the image
`ghcr.io/lyeve-labs/lyeve-console`. [The admin image](https://lyeve.com/docs/deploy/docker/#the-admin-image) lists its
settings and the routing it needs.
[Run the engine and the console together](https://lyeve.com/docs/getting-started/engine-and-console/) shows the
two side by side on one address.

## Next

- [Engine on Fly.io](https://lyeve.com/docs/deploy/engine-fly/): another host that publishes both APIs.
- [Production checklist](https://lyeve.com/docs/deploy/production-checklist/): what to confirm before real traffic.
