Article
Containerize Legacy PHP Applications
Use Docker to pin PHP versions and extensions for legacy apps when it improves parity—without pretending containers alone modernize the code.
Containers help when the pain is environment drift: “works on my PHP 8 laptop, production is 7.4 with three missing extensions.” They do not remove SQL injection or abandoned packages. Use Docker to pin the runtime ladder and give developers production-like SAPIs—then keep modernizing the code itself.
When Docker helps
- Pinning PHP minor versions and extensions across laptops and CI
- Reproducing FPM vs CLI differences
- Providing Xdebug without polluting host PHP
When it does not
- As a substitute for fixing platform constraints or autoloading
- When the team cannot operate images in production and local-only containers diverge again
MODERN — pin the runtime
FROM php:8.2-fpm-bookworm
RUN docker-php-ext-install pdo_mysql opcache
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
WORKDIR /var/www/app
Cover volumes and permissions (www-data vs host UIDs), Apache vs nginx+FPM, Composer install during build vs runtime, and database service linking. Generate Xdebug snippets with Docker PHP Xdebug Generator; size pools with PHP-FPM Pool Calculator.
Related reading
- Composer Modernization Center Add Composer to legacy PHP projects, migrate includes to autoloading, set platform constraints, and replace a…
- PHP 5 to Modern PHP: Complete Incremental Migration Guide A deep, production-minded path from PHP 5.x codebases to supported PHP 8.x: removed extensions, charset, PDO,…
- PHP Security Modernization for Legacy Applications Upgrade inherited PHP security practices: prepared statements, password hashing, sessions, CSRF, XSS escaping…
- PHP 7 to PHP 8 Migration Guide Deep guide to PHP 8.0 breaking changes that matter for PHP 7 applications, with upgrade tactics through suppo…
- Inheriting a Legacy PHP Application A first-30-days playbook for developers handed an unfamiliar PHP codebase: runtime truth, risk triage, and sa…