Quickstart cipi.yml Web panel API MCP Ecosystem Guides Docs GitHub Telegram channel
  1. Home
  2. Docs
  3. Apps
  4. Symfony apps

Symfony apps

Symfony with zero-downtime releases: Composer, AssetMapper, a warm cache and Doctrine migrations.

AppsUpdated

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
$ sudo cipi app create --symfony --user=api --domain=api.example.com --repository=git@github.com:acme/api.git --engine=pgsql

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
FlagMeaningDefault
--symfonyThe app type. Also --framework=symfony, or Symfony in the wizard
--repositoryGit URL over SSH. Requiredasked
--db=NAME / --no-dbThe database made with the app, or nonea database named after the app
--enginemariadb or pgsqlthe server's default
--valkey=own|sharedA Valkey instance of the app's own, or the server's shared oneown
--worker[=TRANSPORTS]Messenger workers made with the app: --worker for async, or --worker=high,asyncnone
--scheduler[=NAME]A worker for the Scheduler: scheduler_default, or the schedule you namenone
--docrootThe folder of the front controllerpublic
--node-buildAsset build run in every deploy (Encore, Vite)none
--php, --branch, --envAs 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.

VariableValue
APP_ENVprod
APP_DEBUG0
APP_SECRETGenerated
DEFAULT_URIhttps:// and the app's domain. It follows sudo cipi app edit api --domain=…
DATABASE_URLThe 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_DSNdoctrine://default: messages wait in that database until a worker consumes them
REDIS_HOST, REDIS_PORT, REDIS_PASSWORD, REDIS_URLA Valkey instance of the app's own. REDIS_URL is what Symfony's cache, sessions, lock and Messenger take: %env(REDIS_URL)%
MAILER_DSNnull://null: nothing is sent until you set a real transport
CIPI_APP_USER, CIPI_ENV, CIPI_PHP_VERSION, CIPI_DEPLOY_BRANCHWhat Cipi knows about the app, for your own code
Created withWhat is left out
--no-dbDATABASE_URL and MESSENGER_TRANSPORT_DSN
A server without ValkeyThe REDIS_* lines
--valkey=sharedNothing: 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#

bash
sudo cipi deploy api
sudo cipi deploy api --rollback
Step 1 of 8Clone

The commit of the branch, in a folder of its own.

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).

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#

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.

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 runsphp bin/console messenger:consume async of the live release, under Supervisor
--processesHow many of them. Default 1
--timeoutSeconds before a worker leaves and is started again (--time-limit). Default 3600
--memoryThe same, above this much memory (--memory-limit). Default 256M
Its log~/logs/worker-async.log
On a deploy, and on a rollbackEach 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 transportsconfig/packages/messenger.yaml: what async is, and which messages go to it
A plain cron jobThe 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#

ProblemFix
The deploy stops at bin/console not foundThe repository is not a Symfony project at its root
An exception occurred in the driver during the deployDATABASE_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 FATALsymfony/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 themNo worker runs: sudo cipi worker add api --queue=async
A value changed in the .env has no effectIt was resolved when the container was compiled: console cache:clear as the app's user, or deploy again
Sessions are lost at every deployKeep them in var/sessions (the default file handler), the database or Valkey, not in var/cache

Questions#

QuestionAnswer
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.