# Self-host quickstart

> Start Multica with Docker Compose, log in, and connect your first computer.

Self-hosting Multica has two parts:

| Part | What it runs | Where it lives |
|---|---|---|
| **Multica service** | Web, API, and PostgreSQL | One machine with Docker installed |
| **Computer** | The Multica daemon and AI coding tools | The computer developers actually work on |

They can be the same machine or separate ones. Self-hosting replaces only the Multica Cloud part.

This guide uses Docker Compose. For Kubernetes deployments, see the [Self-hosting guide](https://github.com/multica-ai/multica/blob/main/SELF_HOSTING.md#kubernetes-deployment-alternative) in the repository.

## Before you start

The machine running the Multica service needs:

- Docker Engine or Docker Desktop, with `docker compose` working
- Git, Make, curl, and OpenSSL
- Ports `3000` and `8080` free on the machine

Confirm Docker and Compose are available first:

```bash
docker info
docker compose version
```

Multica uses Compose v2, invoked as `docker compose`. The legacy `docker-compose` v1 is not supported.

The computer also needs at least one [AI coding tool](https://www.multica.ai/docs/providers) installed and logged in, such as Claude Code, Codex, or Cursor. The Multica CLI is installed in step 5.

## Start Multica

On the machine that will run the service:

```bash
git clone --depth 1 https://github.com/multica-ai/multica.git
cd multica
make selfhost
```

Running `make selfhost` again reuses the existing `.env` and volumes; it does not regenerate secrets.

### What make selfhost does on first run

1. Create `.env` from `.env.example`
2. Generate a random `JWT_SECRET`, PostgreSQL password, and `MULTICA_VCS_SECRET_KEY` (the encryption key for self-hosted Git integrations)
3. Pull the PostgreSQL, Multica backend, and Multica frontend images
4. Create persistent volumes and start the three containers
5. Wait until the backend starts answering health checks

> **Note:** `make selfhost` pulls published images and does not build the code in your checkout. To test local source, use `make selfhost-build`.
>
> The published images track the newest **release tag**, while a plain `git clone` checks out `main`, which usually runs ahead. If you build anything from this checkout — the CLI, or images via `make selfhost-build` — check out the matching release tag first so built binaries and the running containers stay on the same version:
>
> ```bash
> git fetch --tags --depth 1
> git checkout $(git tag -l 'v*' --sort=-v:refname | head -1)
> ```

## Confirm the services are ready

Check container status:

```bash
docker compose -f docker-compose.selfhost.yml ps
```

`postgres` should show `healthy`, and `backend` and `frontend` should be running. Then check the backend, the database, and migrations:

```bash
curl -fsS http://localhost:8080/readyz
```

The expected response is:

```json
{"status":"ok","checks":{"db":"ok","migrations":"ok"}}
```

The backend container runs database migrations on every startup before serving; there is no manual migration command to run.

## Choose how to access

**Local access**

Open [http://localhost:3000](http://localhost:3000) directly. You also won't need to pass any URLs when running `multica setup self-host` later.

**Remote access**

Docker Compose binds `3000` and `8080` to `127.0.0.1` only. Do not switch this to `0.0.0.0` to expose the ports to the public internet; use a reverse proxy with HTTPS instead.

The example below uses two domains:

- `app.example.com`: the Multica web app
- `api.example.com`: the API, health checks, and daemon connections

First set the public URLs in `.env`:

```bash
FRONTEND_ORIGIN=https://app.example.com
MULTICA_APP_URL=https://app.example.com
MULTICA_PUBLIC_URL=https://api.example.com
```

With this configuration all browser traffic stays on the app domain, so cookies never cross domains and `COOKIE_DOMAIN` is not needed. If the browser talks to the api domain directly instead, you must set it — see [Environment variables](https://www.multica.ai/docs/environment-variables).

Then set up DNS and proxy the local ports with Caddy. Caddy obtains TLS certificates and forwards WebSockets.

**Two domains**

```text
app.example.com {
    # Hand browser WebSockets straight to the backend
    @ws path /ws /ws/*
    handle @ws {
        reverse_proxy 127.0.0.1:8080 {
            flush_interval -1
        }
    }

    # Everything else goes to the frontend, which forwards API and login requests
    handle {
        reverse_proxy 127.0.0.1:3000
    }
}

api.example.com {
    reverse_proxy 127.0.0.1:8080 {
        flush_interval -1
    }
}
```

**Single origin**

```text
multica.example.com {
    # CLI reachability probe: `multica setup` GETs <server-url>/health and
    # needs a 200 — older web releases don't forward it, so route it directly
    handle /health {
        reverse_proxy 127.0.0.1:8080
    }

    # Browser realtime WebSocket — the web image cannot proxy WS upgrades
    handle /ws {
        reverse_proxy 127.0.0.1:8080 {
            flush_interval -1
        }
    }

    # Daemon long-connection WebSocket: daemons dial {server-url}/api/daemon/ws
    # (not /ws). Without this route the handshake fails and the daemon silently
    # falls back to polling
    handle /api/daemon/ws {
        reverse_proxy 127.0.0.1:8080 {
            flush_interval -1
        }
    }

    # Everything else goes to the frontend, which forwards API and login requests
    handle {
        reverse_proxy 127.0.0.1:3000
    }
}
```

**Single origin** (one domain, or one host with one port — common on small servers) routes the daemon-critical paths to the backend explicitly and lets the frontend handle the rest. Point both URLs at it: `FRONTEND_ORIGIN` and `MULTICA_APP_URL` in `.env`, then `--server-url` and `--app-url` in `multica setup self-host`.

After editing `.env`, recreate the containers with `up -d` so the new configuration takes effect:

```bash
docker compose -f docker-compose.selfhost.yml up -d
curl -fsS https://api.example.com/readyz
curl -fsS https://app.example.com/api/config | grep -o '"daemon_server_url":"[^"]*"'
```

The last command prints `daemon_server_url`, the URL daemons use to reach the API. If it prints a `localhost` address, `.env` still carries local defaults: set `FRONTEND_ORIGIN` and `MULTICA_APP_URL` explicitly to the public URLs instead of relying on the `${FRONTEND_PORT}` references copied from `.env.example`, then recreate the containers.

### How daemon_server_url is resolved

`MULTICA_DAEMON_SERVER_URL` when set, then `MULTICA_PUBLIC_URL`, otherwise the app URL — `MULTICA_APP_URL`, falling back to `FRONTEND_ORIGIN`. When neither `MULTICA_APP_URL` nor `FRONTEND_ORIGIN` is set, the field is omitted from the response entirely (so the grep prints nothing), even if `MULTICA_DAEMON_SERVER_URL` or `MULTICA_PUBLIC_URL` is set.

> **Warning:** `docker compose restart` only restarts existing containers and does not re-read `.env`. After changing configuration, run `docker compose -f docker-compose.selfhost.yml up -d` to re-read `.env`.

## Log in and create a workspace

Open `http://localhost:3000` locally, or the `https://app.example.com` you just configured, and enter your email to request a verification code.

No email service is configured by default. After requesting a code, read it from the backend logs:

```bash
docker compose -f docker-compose.selfhost.yml logs backend \
  | grep "Verification code"
```

The logs contain a line like:

```text
[DEV] Verification code for you@example.com: 123456
```

Enter the code and create your first workspace. Once Resend or SMTP is configured, codes are sent by email and members no longer need to read container logs — see [Auth setup](https://www.multica.ai/docs/auth-setup).

> **Warning:** Self-hosted deployments default to `APP_ENV=production`, which disables fixed verification codes. Do not set `MULTICA_DEV_VERIFICATION_CODE` on a public instance.

## Connect a computer

Run the commands below on **the computer that runs your AI coding tools**, which is not necessarily the server running Docker.

> **Warning:** Runs execute with the full permissions of the user running the daemon — they can read and write everything that user can. Run the daemon as a dedicated Unix user, in a container, or in a VM rather than under your personal account. See the [security model](https://www.multica.ai/docs/security-model).

Install the Multica CLI first:

**macOS / Linux**

```bash
curl -fsSL https://raw.githubusercontent.com/multica-ai/multica/main/scripts/install.sh | bash
```

**Windows**

```powershell
irm https://raw.githubusercontent.com/multica-ai/multica/main/scripts/install.ps1 | iex
```

Then point the CLI at your service. Pick where the Multica service runs:

**On this computer**

```bash
multica setup self-host
```

**On another machine**

```bash
multica setup self-host \
  --server-url https://api.example.com \
  --app-url https://app.example.com
```

When the service is on another machine, pass the two URLs you configured above. The command first checks `<server-url>/health`, then opens a browser to complete login. After login it stores local credentials and starts the daemon. A `Server not reachable` error at this step means the probe could not get a 200 from `/health`. There are three likely causes: the proxy forwards everything to a web release that does not forward the path; the proxy does not route `/health` to the backend at all; or a lower-level failure (DNS, TLS, firewall, timeout, 5xx from the backend). See [Troubleshooting](https://www.multica.ai/docs/troubleshooting#multica-setup-reports-the-server-is-not-reachable).

Confirm the connection:

```bash
multica daemon status
```

The output should show:

- `Daemon: running`
- `Agents` listing the AI coding tools installed on this machine
- `Workspaces` greater than `0`

## Complete the first run

Back in Multica, once an online runtime appears in the runtime list, create an agent and assign it your first issue.

When the run shows as completed and the agent's reply appears in the timeline, the self-hosted service, the computer, and the AI coding tool are all connected. For detailed steps, see steps 3-5 of the [quickstart](https://www.multica.ai/docs/cloud-quickstart).

## Common admin commands

Run all of these from the `multica` repository directory:

```bash
# Check status
docker compose -f docker-compose.selfhost.yml ps

# Tail backend logs
docker compose -f docker-compose.selfhost.yml logs -f backend

# Apply .env changes
docker compose -f docker-compose.selfhost.yml up -d

# Stop the services, keeping the volumes
docker compose -f docker-compose.selfhost.yml down
```

> **Warning:** `docker compose down` keeps `pgdata` and `backend_uploads`. Adding `-v` deletes these volumes, including the database; do not run `docker compose down -v` unless you intend to wipe the instance.

## Upgrade

### Check for a pinned image tag

Both images resolve as `${MULTICA_IMAGE_TAG:-latest}` (`docker-compose.selfhost.yml`, `services.backend.image` / `services.frontend.image`), and `.env.example` ships `MULTICA_IMAGE_TAG=latest`.

```bash
grep MULTICA_IMAGE_TAG .env
# MULTICA_IMAGE_TAG=v0.4.5   ← pinned: edit to `latest` (or the release you want) first
```

> **Warning:** **If you pinned `MULTICA_IMAGE_TAG`, the upgrade commands below upgrade nothing.** `pull` just re-fetches that same tag and you stay on the old version — no error, no warning.

### Back up Postgres

Migrations are forward-only, so take a dump before upgrading a deployment you care about:

```bash
docker compose -f docker-compose.selfhost.yml exec -T postgres \
  pg_dump -U multica multica > multica-backup.sql && gzip multica-backup.sql
```

Use your own `POSTGRES_USER` / `POSTGRES_DB` from `.env` if you changed them from the `multica` defaults. Data lives in the named volume `multica_pgdata`, which survives `docker compose down` — but not `down -v`.

> **Warning:** **Do not pipe `pg_dump` straight into `gzip`.** A shell reports the exit status of the *last* command in a pipeline, so `pg_dump … | gzip > backup.sql.gz` exits `0` even when the dump failed — leaving a perfectly valid 20-byte archive containing nothing. Redirecting to a file first makes `pg_dump`'s own exit status the one that counts, and `&&` only compresses a dump that actually succeeded.

### Pull the new images and recreate the containers

On an existing install both commands produce the **same result** — the `selfhost` target in the `Makefile` runs the same `docker compose pull` + `up -d`, and additionally creates `.env` when it is missing and waits on `/health` before printing a status summary. Pick whichever you prefer:

**make selfhost**

```bash
cd multica
git pull --ff-only
make selfhost
```

**docker compose**

```bash
cd multica
git pull --ff-only
docker compose -f docker-compose.selfhost.yml pull
docker compose -f docker-compose.selfhost.yml up -d
```

As in [step 2](#2-confirm-the-services-are-ready), the backend container runs `./migrate up` on startup (`docker/entrypoint.sh`) before serving traffic. There is no separate upgrade command: bringing up the new image *is* the migration step. Watch it happen:

```bash
docker compose -f docker-compose.selfhost.yml logs -f backend
```

Migrations that backfill historical data (such as 103) complete the backfill automatically too. In rare cases the automatic backfill fails with `refusing to drop legacy daily rollups` — see [Troubleshooting](https://www.multica.ai/docs/troubleshooting#migration-103-blocks-an-upgrade).

### Verify with `/readyz`, not `/health`

```bash
curl -s localhost:8080/readyz
# {"status":"ok","checks":{"db":"ok","migrations":"ok"}}
```

Anything other than HTTP 200 with both checks `ok` means the new version did not finish migrating — check the backend logs before sending traffic at it.

`/health` is a **liveness** probe — it returns `{"status":"ok"}` as long as the process is up, including when migrations failed. `/readyz` (`readyHandler`, registered in `server/cmd/server/router.go`; `/healthz` is an alias) checks the database and the applied migration set, so it is the one that catches a bad upgrade.

### What git pull actually does

`git pull` updates **`docker-compose.selfhost.yml` itself** — new environment variables, new services, changed healthchecks. It is **not** how you get a new Multica version.

The version you end up running is resolved by `docker compose pull`, which asks GHCR what the tag points at right now. A checkout that is months out of date will still pull today's `latest` images; conversely, `git pull` alone changes nothing until you pull images and recreate the containers.

### Your .env is not overwritten

`make selfhost` only generates `.env` when the file is **missing**. Re-running it on an existing install leaves your `JWT_SECRET`, Postgres password, email settings, and `FRONTEND_ORIGIN` exactly as they were.

### Upgrading on Kubernetes

Helm has its own upgrade path: set `images.backend.tag` / `images.frontend.tag` to the release you want in your values file, then `helm upgrade`. Changing the tag changes the pod spec, so Kubernetes pulls the new image and rolls the Deployments — this is the reliable route.

`kubectl -n multica rollout restart` is **not** an upgrade on its own. The chart ships `pullPolicy: IfNotPresent` (`deploy/helm/multica/values.yaml`), so a node that already has that tag cached reuses the old image and the restart silently changes nothing — the same class of trap as a pinned `MULTICA_IMAGE_TAG`. If you want to track a floating tag that way, set `images.backend.pullPolicy` / `images.frontend.pullPolicy` to `Always` first. See the [Self-hosting guide](https://github.com/multica-ai/multica/blob/main/SELF_HOSTING.md#kubernetes-deployment-alternative).

## Common issues

| Symptom | Check first |
|---|---|
| `/readyz` does not return `ok` | Run `docker compose -f docker-compose.selfhost.yml logs backend postgres`. |
| No verification code arrives | Request a code, then search the backend logs for `Verification code`. |
| `setup self-host` reports the server is unreachable | From the computer, request `https://api.example.com/health` to confirm DNS, TLS, and the reverse proxy are all reachable. A 404 means the proxy sends `/health` to an older web release that does not forward it — route it to the backend ([Troubleshooting](https://www.multica.ai/docs/troubleshooting#multica-setup-reports-the-server-is-not-reachable)). |
| The daemon lists no `Agents` | Confirm the AI coding tools are on `PATH` and logged in, then run `multica daemon restart`. |
| Issues stay queued | Run `multica daemon status` to confirm the daemon is running and connected to the workspace. |

For more scenarios, see [Troubleshooting](https://www.multica.ai/docs/troubleshooting).

## Next steps

- [Auth setup](https://www.multica.ai/docs/auth-setup) — configure email, Google login, and signup scope.
- [Environment variables](https://www.multica.ai/docs/environment-variables) — the full server configuration reference.
- [Self-hosting guide](https://github.com/multica-ai/multica/blob/main/SELF_HOSTING.md) — Kubernetes, upgrades, and manual deployment.
- [Desktop app](https://www.multica.ai/docs/desktop-app) — connect Desktop to a self-hosted service.
