Docs cipi.yml Web panel API MCP Ecosystem Guides Compare GitHub Telegram channel
  1. Home
  2. Guides
  3. Zero-downtime deploys for Symfony, WordPress and any PHP app
PHP, WordPress & e-commerce

Zero-downtime deploys for Symfony, WordPress and any PHP app

Atomic releases with instant rollback for the PHP apps that aren't Laravel, on a Cipi server — the releases/current layout, a Deployer recipe for Symfony, WordPress and plain PHP, and pipelines for GitHub Actions and GitLab CI, with or without Deployer.

By Updated 9 min read

On a Cipi server, zero-downtime releases are built in for Laravel apps: Cipi knows the framework and drives Deployer for you. A Symfony app, a WordPress site or a plain PHP project is a custom app, and sudo cipi deploy pulls its branch into ~/htdocs in place — for a moment visitors get new code with the old vendor/, and there is nothing to roll back to.

This guide gives those apps the same thing Laravel apps have: a new folder per release, one atomic switch, an instant rollback. You write the recipe once — with Deployer, or as a plain GitHub Actions or GitLab CI pipeline — and nothing on the server has to change.

The example is a Symfony app called billing. What changes for WordPress and for plain PHP is said at each step.

1. The layout#

/home/billing/htdocs/
├── releases/
│   ├── 41/                  # every deploy gets a folder of its own
│   ├── 42/
│   └── 43/
├── shared/                  # what survives a deploy
│   ├── .env.local           #   configuration and passwords
│   ├── var/log/             #   logs
│   └── public/uploads/      #   what users upload
└── current -> releases/43   # the live release: a link, switched in one step

A deploy builds releases/44 next to the live one — code, Composer, cache, migrations — while releases/43 keeps answering. When it is ready, current is pointed at it with a single rename. A rollback points it back.

Why it is safe on Cipi, with nothing to configure:

Nginx follows the linkThe vhost of a custom app serves ~/htdocs/<docroot>, and the docroot can be a path through current. The link is read at every request
PHP gets the real pathThe vhost passes PHP the resolved path of the script ($realpath_root): …/releases/43/public/index.php, never …/current/…. A request that started on 43 finishes on 43; OPcache sees 44 as new files and compiles them — no reset, no reload
One userPHP-FPM runs as the app's own user, the one that deploys: nothing to chmod, no ACL
Inside the app's wallsReleases live under /home/billing, where open_basedir already confines the app

2. Create the app with its docroot inside current#

The document root of a custom app is chosen when it is created, so create it pointing through the link:

bash
sudo cipi app create --custom --user=billing --domain=billing.example.com \
    --docroot=current/public --php=8.4 --db=billing

Asked about Git, press Enter: the releases are made by your recipe, not by sudo cipi deploy. Save the summary — the database password is shown once.

App--docrootShared filesShared folders
Symfonycurrent/public.env.localvar/log, public/uploads
WordPress with Bedrockcurrent/web.envweb/app/uploads
WordPress in your own repositorycurrentwp-config.phpwp-content/uploads
Plain PHPcurrent, or current/public.env or config.phpuploads, storage

Then, as the app's user, make room for the link and put in shared/ what is not in Git:

bash
ssh billing@your-server            # your admin key opens every app's shell
rm -rf ~/htdocs/current            # the Coming soon page Cipi put there: `current` must be free
mkdir -p ~/htdocs/shared
nano ~/htdocs/shared/.env.local && chmod 600 ~/htdocs/shared/.env.local
bash
# ~/htdocs/shared/.env.local
APP_ENV=prod
APP_SECRET=a-long-random-string
DATABASE_URL="mysql://billing:PASSWORD@127.0.0.1:3306/billing?serverVersion=mariadb-11.4.0"

HTTPS does not wait for the first deploy: sudo cipi ssl install billing as soon as the DNS points at the server.

A WordPress that updates itself is not for releases. A plugin installed or updated from the dashboard is written into the live release and is gone at the next deploy. Use releases for a WordPress that lives in Git — Bedrock, or your own repository with define( 'DISALLOW_FILE_MODS', true ); — and keep the classic one as a normal custom app.

3. A key for your pipeline#

The deploy runs as the app's user, not as cipi: a key that can only reach this one app — its files, its PHP, nothing else on the server, no sudo cipi.

bash
# on your laptop
ssh-keygen -t ed25519 -C "deploy-billing" -f ./deploy_billing -N ""

# let the app accept keys of its own from outside, then add this one
ssh cipi@your-server "sudo cipi ssh apps enable billing"
ssh billing@your-server "cat >> ~/.ssh/authorized_keys" < ./deploy_billing.pub

Append, never overwrite: the file already holds a key Cipi uses. Then store three secrets in your CI — the names the CI/CD recipes of the docs use:

SecretValue
SERVER_HOSTThe server's IP or hostname
SERVER_SSH_KEYThe whole private key: cat ./deploy_billing — then delete both local files
SERVER_KNOWN_HOSTSssh-keyscan -t ed25519 your-server, after checking the fingerprint (how)

sudo cipi ssh apps enable also lets the app's own password in from outside. It is long and random, and Fail2ban watches the port; change it with sudo cipi app reset-password billing if it was ever shared. The other apps stay as they were.

With Deployer the server also reads your repository: give it the app's read-only deploy key — sudo cipi deploy billing --key prints it — under Deploy keys of the repository. Building in CI (step 7) needs no such key.

4. Deployer: one recipe#

bash
composer require --dev deployer/deployer
php
<?php
// deploy.php — in the root of the repository
namespace Deployer;

require 'recipe/common.php';

set('application', 'billing');
set('repository', 'git@github.com:acme/billing.git');
set('keep_releases', 5);

// On a Cipi server: the app's own PHP, Composer run with it, one user that owns every file
set('bin/php', '/usr/bin/php8.4');
set('bin/composer', '/usr/bin/php8.4 /usr/local/bin/composer');
set('writable_mode', 'chmod');
set('writable_dirs', []);

// What survives a deploy: linked from shared/ into every release
set('shared_files', ['.env.local']);
set('shared_dirs', ['var/log', 'public/uploads']);

host(getenv('SERVER_HOST') ?: '203.0.113.10')
    ->set('remote_user', 'billing')
    ->set('deploy_path', '/home/billing/htdocs');

// Before the switch, in the new release, while the old one still answers
task('app:build', function () {
    run('cd {{release_path}} && {{bin/php}} bin/console cache:clear --no-interaction');
    run('cd {{release_path}} && {{bin/php}} bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration');
});

// After the switch: Cipi's page cache, if it is on (it does nothing when it is off)
task('cipi:page-cache', function () {
    run('sudo -n /usr/local/bin/cipi-cache-clear billing || true');
});

task('deploy', [
    'deploy:prepare',      // lock, releases/N, the code from Git, the links to shared/
    'deploy:vendors',      // composer install --no-dev, in the release
    'app:build',
    'deploy:publish',      // current → releases/N in one step, old releases removed, unlock
]);

after('deploy:symlink', 'cipi:page-cache');
after('rollback', 'cipi:page-cache');
after('deploy:failed', 'deploy:unlock');
LineWhy, on Cipi
bin/php, bin/composerphp in the app's shell is the server's default version: name the app's own
writable_dirs emptyPHP-FPM is the same user that deploys: every file is writable already
deploy_path~/htdocs, the folder Cipi serves. current/public inside it is the docroot of step 2
app:build before deploy:publishA step that fails stops the deploy there: nothing was switched, the old release is still live
cipi:page-cacheThe pages Nginx keeps belong to Nginx's user; this is the one command the app's user may ask root for

The first deploy, from your laptop:

bash
vendor/bin/dep deploy

WordPress and plain PHP#

Only the middle of the recipe changes.

php
// WordPress with Bedrock — docroot current/web
set('shared_files', ['.env']);
set('shared_dirs', ['web/app/uploads']);

task('deploy', [
    'deploy:prepare',
    'deploy:vendors',      // WordPress itself, the plugins and the themes come from Composer
    'deploy:publish',
]);
php
// WordPress in your own repository, no Composer — docroot current
set('shared_files', ['wp-config.php']);
set('shared_dirs', ['wp-content/uploads']);

task('deploy', [
    'deploy:prepare',
    'deploy:publish',
]);
php
// Plain PHP — docroot current, or current/public
set('shared_files', ['.env']);                 // or config.php: whatever holds the passwords
set('shared_dirs', ['uploads', 'storage']);

task('deploy', [
    'deploy:prepare',
    'deploy:vendors',      // only with a composer.json
    'app:build',           // your own: a migration script, a cache to warm
    'deploy:publish',
]);

A shared file must exist in ~/htdocs/shared/ before the first deploy (wp-config.php, .env), as .env.local did in step 2: Deployer links it, it does not write it.

5. From GitHub Actions#

Tests first; the deploy only if they pass; a health check after it, and a rollback if the site doesn't answer.

yaml
# .github/workflows/deploy.yml
name: Test and deploy
on:
  push:
    branches: [main]

concurrency:
  group: deploy-production      # one deploy at a time, queued in order
  cancel-in-progress: false

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: "8.4"     # the version your app uses
      - run: composer install --no-interaction --prefer-dist
      - run: vendor/bin/phpunit  # your tests

  deploy:
    needs: test
    runs-on: ubuntu-latest
    environment: production      # optional: required reviewers, protected secrets
    env:
      SERVER_HOST: ${{ secrets.SERVER_HOST }}
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: "8.4"
      - run: composer install --no-interaction --prefer-dist   # brings vendor/bin/dep
      - name: Set up SSH
        run: |
          mkdir -p ~/.ssh && chmod 700 ~/.ssh
          printf '%s\n' "${{ secrets.SERVER_SSH_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          printf '%s\n' "${{ secrets.SERVER_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
      - name: Deploy
        run: vendor/bin/dep deploy
      - name: Check, roll back if unhealthy
        run: |
          curl -fsS --retry 5 --retry-delay 5 --retry-all-errors https://billing.example.com/ >/dev/null \
            || { vendor/bin/dep rollback; exit 1; }

Roll back only when the deploy succeeded and the check then fails, as above. When dep deploy itself fails, nothing was switched: a rollback there would go one release too far back.

6. From GitLab CI/CD#

The same on GitLab.com and on a GitLab of your own. The three secrets go under Settings → CI/CD → Variables, Masked and Protected.

yaml
# .gitlab-ci.yml
stages: [test, deploy]

test:
  stage: test
  image: composer:2
  script:
    - composer install --no-interaction --prefer-dist
    - vendor/bin/phpunit

deploy:
  stage: deploy
  image: composer:2
  resource_group: production         # one deploy at a time
  environment: production
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
  before_script:
    - apk add --no-cache openssh-client
    - eval $(ssh-agent -s)
    - echo "$SERVER_SSH_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh && chmod 700 ~/.ssh
    - echo "$SERVER_KNOWN_HOSTS" > ~/.ssh/known_hosts
  script:
    - composer install --no-interaction --prefer-dist   # brings vendor/bin/dep
    - vendor/bin/dep deploy
    - curl -fsS --retry 5 --retry-delay 5 --retry-all-errors https://billing.example.com/ >/dev/null || { vendor/bin/dep rollback; exit 1; }

composer:2 runs the newest PHP. For a project pinned to an older one, use an image with that PHP and Composer in it.

7. Without Deployer: build in CI, ship the result#

The other way round: the pipeline runs Composer (and npm, if you have a front end), uploads the finished release with rsync, and a short script on the server links, prepares and switches. The server never runs Composer or npm, and never reads your repository.

Two scripts live in the repository, in deploy/. They travel with every release.

bash
#!/usr/bin/env bash
# deploy/release.sh — run on the server, from inside the release that was just uploaded
set -euo pipefail

RELEASE="$(cd "$(dirname "$0")/.." && pwd -P)"   # /home/billing/htdocs/releases/20261129101500
BASE="$(dirname "$(dirname "$RELEASE")")"         # /home/billing/htdocs
PHP=/usr/bin/php8.4                               # the app's PHP
KEEP=5                                            # releases kept for a rollback

[ "$(basename "$(dirname "$RELEASE")")" = releases ] || { echo "Run it from releases/<name>/deploy/" >&2; exit 1; }
# A release that fails before the switch is deleted: it must never be what a rollback goes back to
trap 'cd "$BASE" && rm -rf "$RELEASE"' ERR

# 1. What survives a deploy lives in shared/ and is linked into the release
mkdir -p "$BASE/shared/var/log" "$BASE/shared/public/uploads"
ln -sfn "$BASE/shared/.env.local" "$RELEASE/.env.local"
for dir in var/log public/uploads; do
    rm -rf "${RELEASE:?}/$dir" && mkdir -p "$(dirname "$RELEASE/$dir")"
    ln -sfn "$BASE/shared/$dir" "$RELEASE/$dir"
done

# 2. Get the release ready while the old one still answers
cd "$RELEASE"
"$PHP" bin/console cache:clear --no-interaction
"$PHP" bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration

# 3. Switch, in one step: a rename is atomic, no request sees half a link
ln -sfn "releases/$(basename "$RELEASE")" "$BASE/current.new"
mv -T "$BASE/current.new" "$BASE/current"
trap - ERR

# 4. After the switch: Cipi's page cache (if it is on), then the oldest releases
sudo -n /usr/local/bin/cipi-cache-clear "$(whoami)" || true
cd "$BASE/releases" && ls -1d -- */ | sort | head -n -"$KEEP" | xargs -r rm -rf --
echo "Live: $(basename "$RELEASE")"
bash
#!/usr/bin/env bash
# deploy/rollback.sh — back to the release before the live one
set -euo pipefail

RELEASE="$(cd "$(dirname "$0")/.." && pwd -P)"
BASE="$(dirname "$(dirname "$RELEASE")")"
live="$(basename "$(readlink "$BASE/current")")"
prev="$(cd "$BASE/releases" && ls -1d -- */ | tr -d / | sort | awk -v live="$live" '$0 < live' | tail -n 1)"
[ -n "$prev" ] || { echo "No release before $live" >&2; exit 1; }

ln -sfn "releases/$prev" "$BASE/current.new"
mv -T "$BASE/current.new" "$BASE/current"
sudo -n /usr/local/bin/cipi-cache-clear "$(whoami)" || true
echo "Rolled back: $live -> $prev"

For WordPress or plain PHP, change two places in release.sh: the shared file and folders of the table in step 2, and the commands of part 2 (none at all for a WordPress without migrations of its own).

GitHub Actions — the deploy job, in place of the one of step 5:

yaml
  deploy:
    needs: test
    runs-on: ubuntu-latest
    environment: production
    env:
      SERVER: billing@${{ secrets.SERVER_HOST }}
      BASE: /home/billing/htdocs
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: "8.4"     # the app's version on the server
      - name: Build
        run: APP_ENV=prod composer install --no-dev --optimize-autoloader --no-interaction --prefer-dist
      - name: Set up SSH
        run: |
          mkdir -p ~/.ssh && chmod 700 ~/.ssh
          printf '%s\n' "${{ secrets.SERVER_SSH_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          printf '%s\n' "${{ secrets.SERVER_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
      - name: Upload, prepare, switch
        run: |
          REL=$(date -u +%Y%m%d%H%M%S)
          ssh "$SERVER" "mkdir -p $BASE/releases/$REL"
          rsync -az --delete --exclude='.git*' --exclude='/var' --exclude='/tests' --exclude='.env.local' \
            ./ "$SERVER:$BASE/releases/$REL/"
          ssh "$SERVER" "bash $BASE/releases/$REL/deploy/release.sh"
      - name: Check, roll back if unhealthy
        run: |
          curl -fsS --retry 5 --retry-delay 5 --retry-all-errors https://billing.example.com/ >/dev/null \
            || { ssh "$SERVER" "bash $BASE/current/deploy/rollback.sh"; exit 1; }

GitLab CI/CD — the deploy job, in place of the one of step 6:

yaml
deploy:
  stage: deploy
  image: composer:2
  resource_group: production
  environment: production
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
  variables:
    SERVER: billing@$SERVER_HOST
    BASE: /home/billing/htdocs
  before_script:
    - apk add --no-cache openssh-client rsync
    - eval $(ssh-agent -s)
    - echo "$SERVER_SSH_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh && chmod 700 ~/.ssh
    - echo "$SERVER_KNOWN_HOSTS" > ~/.ssh/known_hosts
  script:
    - APP_ENV=prod composer install --no-dev --optimize-autoloader --no-interaction --prefer-dist
    - REL=$(date -u +%Y%m%d%H%M%S)
    - ssh "$SERVER" "mkdir -p $BASE/releases/$REL"
    - rsync -az --delete --exclude='.git*' --exclude='/var' --exclude='/tests' --exclude='.env.local' ./ "$SERVER:$BASE/releases/$REL/"
    - ssh "$SERVER" "bash $BASE/releases/$REL/deploy/release.sh"
    - curl -fsS --retry 5 --retry-delay 5 --retry-all-errors https://billing.example.com/ >/dev/null || { ssh "$SERVER" "bash $BASE/current/deploy/rollback.sh"; exit 1; }
DeployerBuild in CI
Where Composer runsOn the server, in the new releaseIn the pipeline
The server reads GitYes, with the app's deploy keyNo
Also from your laptopvendor/bin/dep deployNot without the pipeline
Locks, rollback, cleanupIncludedThe two scripts above

8. Roll back#

WithCommand
Deployervendor/bin/dep rollback — from your laptop or a pipeline
The scriptsssh billing@your-server 'bash ~/htdocs/current/deploy/rollback.sh'
By hand, any timecd ~/htdocs && ln -sfn releases/42 current.new && mv -T current.new current

A rollback switches the code. The database stays where the migrations left it — which is the reason for the first rule below.

Migrations, cron and workers#

Migrations run before the switchFor a moment the old code runs on the new schema. Add first, remove later: a new column in this release, the code that needs it in the same one, the drop of the old column in the next
Cron and workers start from currentIn the app user's crontab: * * * * * /usr/bin/php8.4 /home/billing/htdocs/current/bin/console messenger:consume async --time-limit=55 --quiet. Each run picks up the live release; a short time limit means no worker stays on old code for long
Never write into a releaseWhat the app creates and must keep — uploads, generated files, SQLite — belongs in a shared folder. What it can rebuild (var/cache) belongs in the release
SessionsPHP's default session files are outside the app and survive. If the app keeps them in its own folder (var/sessions), share that folder
Backupsshared/ and the database are what matters. Five releases are five copies of the code: to leave them out of the archives, sudo cipi backup profile edit <profile> --exclude-paths='billing:htdocs/releases' (paths left out)
Know when it breakssudo cipi health set billing --url=https://billing.example.com/ --expect=200: Cipi probes the site every five minutes and alerts you after three failures

Caches#

CacheAfter a deploy
OPcacheNothing to do. Every release has paths of its own, so PHP compiles the new files at the first request. The scripts of old releases stay in OPcache's memory until PHP-FPM restarts: if you deploy many times a day, give it room — sudo cipi ini set opcache.memory_consumption=256 — or restart PHP at a quiet hour (sudo cipi service restart php)
Page cacheEmptied by the last step of every recipe here: sudo /usr/local/bin/cipi-cache-clear billing. To purge only some pages: … billing /pricing/ '/blog/*'
The app's own (var/cache, a compiled container)Built in the new release before the switch, by cache:clear

An app that already exists#

The docroot of a custom app is fixed at creation. Two ways to get there:

The app's docroot todayWhat to do
A folder: public, web, wwwDeploy the first release as above (it lands in ~/htdocs/releases/1, next to the old files). Then, once: cd ~/htdocs && mv public public.old && ln -s current/public public. Nginx now goes public → current → releases/N; the old files can go. From then on deploy with the recipe only, not with sudo cipi deploy
htdocs itselfCreate a second app with --docroot=current, deploy and test it on a temporary domain, then give it the real one: sudo cipi app edit <old> --domain=old.example.com, sudo cipi app edit <new> --domain=example.com

Troubleshooting#

ProblemFix
There is a directory (not symlink) at …/currentThe Coming soon folder is still there: rm -rf ~/htdocs/current, as the app's user
The domain answers 404 right after creating the appNothing is deployed yet: current comes with the first deploy
Permission denied (publickey) from the pipelineApp logins from outside are off: sudo cipi ssh apps enable billing. The public key must be a line of /home/billing/.ssh/authorized_keys
Permission denied on git@github.com during deploy:update_codeThe server reads the repository with the app's deploy key: sudo cipi deploy billing --key, added to the repository as read-only
php or composer is the wrong versionCall them by path: /usr/bin/php8.4, /usr/bin/php8.4 /usr/local/bin/composer
The first deploy fails in cache:clearshared/.env.local is missing or empty: Symfony started in dev without its dev packages
Old pages after a deployCipi's page cache is on and the recipe doesn't empty it: add the cipi-cache-clear step
Uploads are gone after a deployThey were written into the release: add their folder to the shared ones, and move the files to ~/htdocs/shared/
A WordPress plugin lost a path after a deployIt saved an absolute path with the release in it (…/releases/42/…). Save its settings again, or prefer plugins that don't store paths
Deploy locked (Deployer)A deploy was interrupted: vendor/bin/dep deploy:unlock

Questions

Why isn't this built in, as it is for Laravel?

Cipi knows how a Laravel app is laid out — what is shared, what runs before the switch, which workers restart — so it automates all of it. It can't know that of an arbitrary PHP app. Here you write those few lines once, in a recipe or a script that lives in your repository.

Is it really zero downtime?

The switch is one rename of a link, and Cipi's vhost gives PHP the real path of the release at every request: a request runs entirely on the old code or entirely on the new one. What can still hurt is a database migration the old code can't live with — keep migrations backward compatible.

Does `sudo cipi deploy` still work for this app?

No: the app has no repository in Cipi, so there is nothing for it to pull. Cipi's Deploy button, deploy log and audit ledger are for the deploys Cipi runs itself; for these, your pipeline is the record.

Deployer or plain CI?

Deployer when you want one recipe that also runs from your laptop, with locks and rollback included. Plain CI when you'd rather build once in the pipeline — Composer, npm — and ship the result, so the server never runs a build and never needs to read your repository.

Can I use it for a WordPress I update from the dashboard?

No. A plugin installed from the dashboard is written into the live release and is gone at the next deploy. Releases are for a WordPress that lives in Git (Bedrock, or your own repository); the classic one stays a normal custom app.

What about the app I already have?

The document root is chosen when the app is created. With a docroot folder (public, web) that folder can become a link into current; an app served from htdocs itself is better recreated — see the section at the end.

Does it work with the page cache?

Yes. Empty it after the switch with sudo /usr/local/bin/cipi-cache-clear <app>, which the app's user may run: the recipes here do it.

Do I need the web panel for this?

No. Everything here is the CLI, your repository and your CI.

Try it on your own server

Free and open source. One command on a fresh Ubuntu 24.04 or 26.04 VPS.

wget -O - https://cipi.sh/setup.sh | bash
Read the quickstart