Symfony apps
Symfony with zero-downtime releases: Composer, AssetMapper, a warm cache and Doctrine migrations.
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.
$ sudo cipi app create --symfony --user=api --domain=api.example.com --repository=git@github.com:acme/api.git --engine=pgsql
Create one#
# 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 instance of the app's own, or the server's shared one | own |
--worker[=TRANSPORTS] | Messenger workers made with the app: --worker for async, or --worker=high,async | none |
--scheduler[=NAME] | A worker for the Scheduler: 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 |
Where things live#
/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 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 |
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.
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#
sudo cipi deploy api sudo cipi deploy api --rollback
The commit of the branch, in a folder of its own.
Linked in before anything runs, so Composer's scripts already see the production environment.
composer install --no-dev --optimize-autoloader.
Your build command, then importmap:install and asset-map:compile when AssetMapper is installed.
The production cache of this release, warmed before it serves a request.
When doctrine/doctrine-migrations-bundle is installed. Off with --no-migrate.
One step, with the lock released if anything above failed.
Each Messenger worker finishes its message, then starts again on this release.
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).
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 has the pattern; it is the same for Doctrine.
Console#
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#
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.
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:
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:
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. 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. The code comes back from Git. |
| Step by step? | Deploy Symfony on a VPS. |