PHP 7: Maintaining and Upgrading Legacy Apps · Operating Legacy PHP in Production
Containerizing a Legacy PHP App
Make the old app reproducible with Docker before changing it further.
Containerizing a legacy app pins its runtime (PHP version, extensions, ini settings) so it runs identically everywhere and can be upgraded by changing one line. Start from php:7.4-fpm (images still exist but receive no updates), install required extensions, copy the production ini, and mount or bake the code. Use docker compose for local dependencies (MySQL, Redis). Then create a php:8.x variant for the upgrade.
# Dockerfile.legacy
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y --no-install-recommends libzip-dev libpng-dev \
&& docker-php-ext-install pdo_mysql mysqli zip gd opcache \
&& rm -rf /var/lib/apt/lists/*
COPY docker/php.ini /usr/local/etc/php/php.ini
WORKDIR /var/www/html
COPY . .
USER www-data
Common pitfalls
- Using EOL images without understanding they get no security updates.
- Writing uploads/sessions inside the container filesystem.
- Missing extensions only discovered at runtime.
Key points
- Containers pin the runtime
- Externalize uploads and sessions
- Build a PHP 8 variant for the upgrade
Further reading: Official PHP Docker images
Practice questions
Why containerize a legacy app before upgrading it?
Answer
It documents and reproduces the exact runtime, makes environments consistent, and lets you test the upgrade by changing the base image.
Where should uploads and sessions live for containerized apps?
Answer
Outside the container: object storage or a mounted volume for files, and Redis/database for sessions, so containers stay disposable.
Open in the app to mark lessons complete, take notes and track your progress.