# Symfony apps

> Deploy Symfony from Git with atomic releases and rollback: composer install, AssetMapper, a warm prod cache, Doctrine migrations and a shared .env.local.

URL: https://cipi.sh/docs/symfony-apps · Last updated: 2026-12-01 · Section: Apps

A Symfony app deploys with zero downtime, the way a Laravel app does: Composer, assets, a warm cache and Doctrine migrations run in a new release beside the live one, and one switch puts it online.

A Symfony app with PostgreSQL:

```console
$ sudo cipi app create --symfony --user=api --domain=api.example.com --repository=git@github.com:acme/api.git --engine=pgsql
→ Creating 'api' (symfony)...
✓ User   ✓ Directories   ✓ Deploy key
✓ Database api (PostgreSQL)
✓ shared/: .env (the release's .env.local) with DATABASE_URL, Valkey, var/log,var/sessions
✓ PHP-FPM 8.5 (+ Git webhook)   ✓ Nginx → api.example.com
✓ Deploy trigger   ✓ Deployer   ✓ Permissions

  Runtime:    Symfony — PHP-FPM, zero-downtime releases
  Docroot:    /home/api/current/public
  Shared      ~/shared/.env — each release's .env.local; ~/shared/var/log, ~/shared/var/sessions
  Next: cipi deploy api   then cipi ssl install api
```

## Create one

```bash
# A database named after the app, and a ready .env.local
$ sudo cipi app create --symfony --user=api --domain=api.example.com \
    --repository=git@github.com:you/api.git

# PostgreSQL, a named database, Webpack Encore
$ sudo cipi app create --symfony --user=crm --domain=crm.example.com \
    --repository=git@github.com:you/crm.git --db=crm_prod --engine=pgsql \
    --node-build='npm ci && npm run build'

# With a Messenger worker and the Scheduler
$ sudo cipi app create --symfony --user=jobs --domain=jobs.example.com \
    --repository=git@github.com:you/jobs.git --worker --scheduler
```

| Flag | Meaning | Default |
| --- | --- | --- |
| `--symfony` | The app type. Also `--framework=symfony`, or *Symfony* in the wizard | |
| `--repository` | Git URL over SSH. Required | asked |
| `--db=NAME` / `--no-db` | The database made with the app, or none | a database named after the app |
| `--engine` | `mariadb` or `pgsql` | the server's default |
| `--valkey=own\|shared` | A [Valkey](https://cipi.sh/docs/valkey) instance of the app's own, or the server's shared one | `own` |
| `--worker[=TRANSPORTS]` | [Messenger workers](https://cipi.sh/docs/symfony-apps#workers) made with the app: `--worker` for `async`, or `--worker=high,async` | none |
| `--scheduler[=NAME]` | A worker for the [Scheduler](https://cipi.sh/docs/symfony-apps#workers): `scheduler_default`, or the schedule you name | none |
| `--docroot` | The folder of the front controller | `public` |
| `--node-build` | Asset build run in every deploy (Encore, Vite) | none |
| `--php`, `--branch`, `--env` | As for [every app](https://cipi.sh/docs/create-app#flags) | |

## Where things live

```text
/home/api/
├── current -> releases/8         # Nginx serves current/public
├── releases/7/ 8/                # one folder per deploy
└── shared/
    ├── .env                      # linked into each release as .env.local
    ├── var/log/                  # the app's log
    └── var/sessions/             # file sessions survive a deploy
```

`var/cache` is each release's own: the new cache is built before the release goes live, and the old one keeps serving until the switch.

## Environment

`~/shared/.env` is linked into every release as **`.env.local`**. The `.env` committed in your repository keeps its defaults, and what the server says wins, as Symfony's own loading order has it.

Cipi writes it when the app is created, with what a Laravel app's first `.env` has, under the names Symfony's own recipes read. The first deploy works without editing it.

| Variable | Value |
| --- | --- |
| `APP_ENV` | `prod` |
| `APP_DEBUG` | `0` |
| `APP_SECRET` | Generated |
| `DEFAULT_URI` | `https://` and the app's domain. It follows `sudo cipi app edit api --domain=…` |
| `DATABASE_URL` | The database made with the app: `mysql://…` or `postgresql://…` on `127.0.0.1`, with the server's version as `serverVersion`, so Doctrine does not have to connect to learn it |
| `MESSENGER_TRANSPORT_DSN` | `doctrine://default`: messages wait in that database until a [worker](https://cipi.sh/docs/symfony-apps#workers) consumes them |
| `REDIS_HOST`, `REDIS_PORT`, `REDIS_PASSWORD`, `REDIS_URL` | A Valkey instance of the app's own. `REDIS_URL` is what Symfony's cache, sessions, lock and Messenger take: `%env(REDIS_URL)%` |
| `MAILER_DSN` | `null://null`: nothing is sent until you set a real transport |
| `CIPI_APP_USER`, `CIPI_ENV`, `CIPI_PHP_VERSION`, `CIPI_DEPLOY_BRANCH` | What Cipi knows about the app, for your own code |

| Created with | What is left out |
| --- | --- |
| `--no-db` | `DATABASE_URL` and `MESSENGER_TRANSPORT_DSN` |
| A server without Valkey | The `REDIS_*` lines |
| `--valkey=shared` | Nothing: `REDIS_*` name the server's shared instance |

> [!NOTE]
> These lines win over the `.env` in your repository. If your project sends Messenger through AMQP or Redis, or mail through a real transport, set its DSN here.

Change it with `sudo cipi app env api`. Symfony reads the file at every request, so a value used through `%env(…)%` applies at once; one the container resolved when it was compiled needs `console cache:clear` or a new deploy.

> [!WARNING]
> A `.env.local.php` in the repository is read by Symfony **instead of** `.env` and `.env.local`, so the server's values would be ignored. The deploy says so when it finds one: remove it from Git.

## Deploy

```bash
$ sudo cipi deploy api
$ sudo cipi deploy api --rollback
```

1. **Clone** — releases/9
   The commit of the branch, in a folder of its own.
2. **Shared** — .env.local, var/log, var/sessions
   Linked in before anything runs, so Composer's scripts already see the production environment.
3. **Composer** — --no-dev
   `composer install --no-dev --optimize-autoloader`.
4. **Assets** — --node-build, AssetMapper
   Your build command, then `importmap:install` and `asset-map:compile` when AssetMapper is installed.
5. **Cache** — cache:clear
   The production cache of this release, warmed before it serves a request.
6. **Migrations** — doctrine:migrations:migrate
   When `doctrine/doctrine-migrations-bundle` is installed. Off with `--no-migrate`.
7. **Switch** — current → releases/9
   One step, with the lock released if anything above failed.
8. **Workers** — messenger:consume
   Each Messenger worker finishes its message, then starts again on this release.

```bash
$ sudo cipi app deploy-config api --no-migrate
$ sudo cipi app deploy-config api --keep-releases=8 --build-timeout=2700
```

Pushes deploy by themselves through Cipi's own webhook, with nothing to install in the project ([auto-deploy](https://cipi.sh/docs/auto-deploy)).

> [!TIP]
> Migrations run before the switch, while the old release is still serving. Write them so that the previous code works on the new schema: add first, remove in a later release. [Zero-downtime migrations](https://cipi.sh/guides/laravel-zero-downtime-migrations) has the pattern; it is the same for Doctrine.

## Console

```bash
$ sudo su - api
$ console about
$ console doctrine:migrations:status
$ console messenger:failed:show
```

`console` is an alias for `php ~/current/bin/console`, on the app's PHP.

## Logs

```bash
$ sudo cipi app logs api --type=laravel
```

reads `~/shared/var/log`, the app's own log. PHP-FPM and Nginx logs are the other [log types](https://cipi.sh/docs/artisan-logs).

## Messenger and the Scheduler

A Messenger worker is one command, the same that adds a queue worker to a Laravel app. `--queue` names the transport:

```bash
$ sudo cipi worker add api --queue=async
$ sudo cipi worker add api --queue=async --processes=3 --timeout=1800 --memory=512M
$ sudo cipi worker list api
$ sudo cipi worker restart api
$ sudo cipi worker remove api async
```

| | |
| --- | --- |
| What runs | `php bin/console messenger:consume async` of the live release, under Supervisor |
| `--processes` | How many of them. Default 1 |
| `--timeout` | Seconds before a worker leaves and is started again (`--time-limit`). Default 3600 |
| `--memory` | The same, above this much memory (`--memory-limit`). Default `256M` |
| Its log | `~/logs/worker-async.log` |
| On a deploy, and on a rollback | Each worker finishes the message in hand and starts again on the release that is live |

**The Scheduler** component is a Messenger transport too. Its worker is one more:

```bash
$ sudo cipi worker add api --queue=scheduler_default
```

Workers are not on by default: Messenger and the Scheduler are components an app may not have. A deploy that finds one installed with no worker tells you the command. To have them from the start, create the app with `--worker` and `--scheduler`.

| Still yours | |
| --- | --- |
| The transports | `config/packages/messenger.yaml`: what `async` is, and which messages go to it |
| A plain cron job | The app's crontab: `sudo su - api`, `crontab -e`, with `php /home/api/current/bin/console …` |

## What Nginx does

Symfony's front controller as its documentation writes it: a path that is a file is served, everything else goes to `index.php`, and no other `.php` file runs.

## Common problems

| Problem | Fix |
| --- | --- |
| The deploy stops at *bin/console not found* | The repository is not a Symfony project at its root |
| `An exception occurred in the driver` during the deploy | `DATABASE_URL` is missing or wrong: `sudo cipi app env api`. An app created with `--no-db` has none |
| *No transport supports the given Messenger DSN "doctrine://default"* | `symfony/doctrine-messenger` is not installed. Install it, or set the DSN of the transport you use in `sudo cipi app env api` |
| A worker shows `FATAL` | `symfony/messenger` is not in the release, or the transport does not exist: `~/logs/worker-<transport>.log` has the error |
| Messages are sent and nothing handles them | No worker runs: `sudo cipi worker add api --queue=async` |
| A value changed in the `.env` has no effect | It was resolved when the container was compiled: `console cache:clear` as the app's user, or deploy again |
| Sessions are lost at every deploy | Keep them in `var/sessions` (the default file handler), the database or Valkey, not in `var/cache` |

## Questions

| Question | Answer |
| --- | --- |
| Which Symfony versions? | Any that runs on the PHP versions Cipi installs: pick the PHP with `--php`. |
| API Platform, EasyAdmin, Sylius? | They are Symfony apps: the same type. Sylius builds its admin assets with `--node-build`. |
| Can I keep my own Deployer recipe? | Yes, on a [custom app](https://cipi.sh/docs/custom-apps#deploys). This type is for when you would rather not maintain one. |
| Is it backed up? | `shared/` (the `.env`, logs, sessions) and the database are in [backups](https://cipi.sh/docs/backups). The code comes back from Git. |
| Step by step? | [Deploy Symfony on a VPS](https://cipi.sh/guides/deploy-symfony). |

---

Index of every page: https://cipi.sh/llms.txt · Everything in one file: https://cipi.sh/llms-full.txt · Source: https://github.com/cipi-sh/cipi (MIT)
