Low-downtime deploys for PHP applications

Published 2026-11-06

What users notice

Most users never notice a deploy that takes a second. They notice one that serves an error page for a minute, or one that mixes old and new files for a moment and produces a strange half-working page. The goal is not mathematical zero downtime but releases nobody can tell happened.

Bind mounts and what they imply

When the application code is bind-mounted into the container, a git pull on the host changes the code the running PHP process serves immediately. That is convenient: PHP changes are live after the pull. It also means a release is not atomic, and that compiled front-end assets need a separate build step before the new HTML refers to them.

Order the work accordingly: build assets first, then update the code, then clear and rebuild caches. Doing it the other way round briefly serves pages that point at assets that do not exist yet.

Maintenance mode as a safety net

Framework maintenance mode is a blunt but useful tool for migrations that cannot run alongside live traffic. Use it sparingly and for seconds, with a friendly page and a retry header, and prefer additive migrations that are safe to run while the old code is still serving.

Expand, then contract

The safest pattern for database changes is two releases. First add the new column or table while the old code ignores it. Deploy code that writes to both. Later, once everything uses the new structure, remove the old one. Each step is compatible with the code running before and after it, so there is never a moment where schema and code disagree.

Verify the right thing

After a deploy, confirm what is actually running on the server: the commit that is checked out, the image that is up, the health endpoint's answer. A successful push proves only that git accepted your commits. Make the deploy command exit non-zero on failure so scripts and humans cannot mistake a failed release for a good one.

A release routine that stays calm

Write the routine down and keep it short: pull the new code, install dependencies if they changed, build front-end assets, run migrations that were written to be safe alongside live traffic, clear and warm caches, then check the result. Each step should be repeatable and safe to run twice, so a failed release can simply be run again.

Automate it with a single command so the order never depends on memory, and have it stop at the first error rather than continue into a half-deployed state.

Rolling back

Decide the rollback plan before the release. For code, that means being able to return to the previous commit quickly. For data, it means that every migration has a tested way back or that the change was additive, so old code keeps working against the new schema. The expand-then-contract pattern makes this almost free: nothing is removed until the new code has run in production for a while.

Small habits that prevent big incidents

  • Deploy to the development environment first and look at it before touching production.
  • Avoid releases when you cannot watch the result.
  • Keep releases small; a one-day change is easier to reason about than a month of them.
  • Tag or note the commit that went live, so you always know what is running.

© 2026 The Good Fellas