# Run LyEve on free hosting

URL: https://lyeve.com/docs/deploy/free-tier-overview/

This recipe runs the engine and a Postgres database at $0 a month: one free account for the
engine, one for the database, wired together with a handful of environment variables. The
result is a headless engine over HTTPS, managed with `curl` or your own tooling.
It suits a demo, a staging environment or a low-traffic project. To compare it with the other
ways to run LyEve, see [Choose where to run LyEve](https://lyeve.com/docs/deploy/).

## Before you start

- An account on an engine host with a free plan: [Render](https://lyeve.com/docs/deploy/engine-render/) or
  [Google Cloud Run](https://lyeve.com/docs/deploy/engine-cloud-run/). Each publishes one of the two APIs. [Railway](https://lyeve.com/docs/deploy/engine-railway/)
  and [Fly.io](https://lyeve.com/docs/deploy/engine-fly/) publish both, but they bill by usage after a trial.
- An account on [Supabase](https://lyeve.com/docs/deploy/database-supabase/) or [Neon](https://lyeve.com/docs/deploy/database-neon/) for the database.
- `openssl` and `curl` on your machine.

## Steps

1. **Create the database.** Make a free Postgres project and copy the connection string its
   page recommends: the session pooler on [Supabase](https://lyeve.com/docs/deploy/database-supabase/), the direct string
   on [Neon](https://lyeve.com/docs/deploy/database-neon/).

2. **Generate the secrets.** Run this three times and keep each value somewhere durable:

   ```bash
   openssl rand -hex 32
   ```

3. **Deploy the engine image** `ghcr.io/lyeve-labs/lyeve-core` on your engine host, following
   its page, with these variables:

   ```text
   DATABASE_URL=<the connection string from step 1>
   DATABASE_MAX_CONNECTIONS=5
   JWT_SECRET=<first secret>
   ENCRYPTION_KEY=<second secret>
   LYEVE_AUDIT_HMAC_KEY=<third secret>
   RATE_LIMIT_RPS=100
   SECURE_COOKIE=true
   CORS_ORIGINS=https://your-app.example.com
   ```

   `APP_ENV` defaults to `production`, which refuses to start without the secrets,
   `RATE_LIMIT_RPS` and `SECURE_COOKIE=true`. [Configuration](https://lyeve.com/docs/reference/configuration/#what-production-refuses)
   lists every check. `CORS_ORIGINS` names the browser apps that will call the Content API.

4. **Check the engine.** Ask the Content API for the engine's public key, or ask the Admin API
   whether setup is needed, whichever your host publishes:

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

   The Admin API answers `{"setup_required":true,"token_source":"log"}`. The setup token is the
   one-time `setup_token` the engine wrote to its standard error at startup. Your host's logs
   show standard error, so search them for `setup_token`.

5. **Create the first administrator.** Follow the [quickstart](https://lyeve.com/docs/getting-started/quickstart/)
   from step 2, against your Admin API URL. On a host that publishes one API, publish port
   `3001` for this step.

## Limits of the free stack

- **Cold starts.** Both free engine hosts stop the container after a period with no traffic:
  Render free web services, and Cloud Run with `--min-instances=0`. The first request after that
  waits for three things: the host starting the container, the database resuming if it slept
  (Neon does), and the engine's own start. The engine logs its share as `boot_ms` on its
  `serving` line, so the log shows how much of a slow first request was the engine.
- **Signing out on restart.** The engine keeps its signing key at `JWT_KEY_PATH`
  (`/var/lib/lyeve/jwt_key.json`) and creates a new one when the file is missing. On a host with
  no persistent disk, every cold start or redeploy makes a new key, and every token issued
  before it stops working. Where the host offers a volume, mount it at `/var/lib/lyeve`, writable
  by uid `65532`. 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 restart still signs everyone out once their
  access token expires, 15 minutes by default.
- **One engine service.** Two services started from the image each create their own key, so a
  token from one is refused by the other. Do not run a second service to publish the other port.
- **Connection limits.** Free Postgres plans cap connections. Keep `DATABASE_MAX_CONNECTIONS`
  small, because a redeploy can briefly run the old and new engine side by side.
- **No disk for media.** Uploads stored on local disk, the default, are lost at a cold start or
  a redeploy. Store them in an S3-compatible bucket. See
  [Object storage](https://lyeve.com/docs/features/object-storage/).
- **No LyEve Console.** The console needs a host that runs a second container behind a proxy.
  See [The console needs a server](https://lyeve.com/docs/deploy/#the-console-needs-a-server-not-vercel-or-cloudflare-pages).
- **No SQLite.** SQLite, Turso and libSQL cannot replace the database. See
  [supported databases](https://lyeve.com/docs/deploy/#supported-databases).

## Next

- [Production checklist](https://lyeve.com/docs/deploy/production-checklist/) before real data goes behind it.
- [Docker Compose](https://lyeve.com/docs/deploy/docker-compose/) to add the console on a server you control.
