Deploy PHP

Deploy checklist

Calm deploys follow a written list: freeze merges, run tests and static analysis, tag the release, copy files, clear caches, smoke test the front page. Ticking boxes in order beats heroic memory every single release.

php tests/check.php

OK: all green, ready to tag

Env files

Secrets and host names live in env files, never in git. Each server keeps its own copy with database logins and keys, while the code reads values by name and falls back to safe local defaults.

$env = parse_ini_file(__DIR__ . "/app.env"); $dbHost = $env["DB_HOST"] ?? "localhost"; echo $dbHost . "\n";

Run migrations

Schema changes ship as numbered migration scripts that run once in order, with each step adding a table or column inside a transaction. Back up the database first, then run the up command and verify the version marker moved.

php migrate.php --up

migrated to version 14

Rollback plan

Every release keeps the previous folder one symlink away, so a bad deploy heals in seconds by pointing the link back. Practice the rollback on staging monthly so the night it matters feels routine.

function rollbackTo(string $release): void { echo "restore " . $release . "\n"; } rollbackTo("release-41");

Next: Catch-up and capstone

Article author: Arthur Isaev