Containerizing a PHP application that was written for a long-lived server is rarely a packaging exercise. The difficulty is that the application has accumulated assumptions about its environment which were true for a decade and stop being true the moment it runs somewhere ephemeral.
These are the patterns that come up repeatedly.
The filesystem is not permanent
Older PHP applications write to disk constantly, uploads, generated files, cache artifacts, session data, logs. On a single long-lived host, that works. In a container it produces files that vanish on restart and, worse, files that exist on one replica and not another.
The symptom is almost never an error. It is a user who uploads a file, gets a success message, and cannot find it afterward, because the request that stored it and the request that read it landed on different replicas.
Externalize state before you containerize: object storage for uploads, a shared cache for sessions, stdout for logs.
Sessions assume a shared disk
PHP's default session handler writes to local files. Two replicas means two session stores and a user who appears to log out at random.
Moving to a shared session backend is straightforward mechanically. The part that takes longer is finding the code that reads session files directly, or that assumes session data survives a deploy.
Configuration is baked in at build time
A config.php committed to the repository, or generated once during
provisioning, becomes an image that is specific to one environment. That defeats
the purpose of building an image once and promoting it.
The migration is mechanical but wide: every configuration value becomes an environment variable read at startup, and secrets stop living in the image entirely.
Cron jobs have no home
Scheduled work that lived in the host's crontab has nowhere obvious to go. Run it in the application container and it runs once per replica. Give it its own container and you now have two images to keep in sync.
Either a scheduler that guarantees single execution, or a work queue with a lock, is required. What does not work is hoping only one replica picks it up.
Shutdown is abrupt
Long-running requests and background work get terminated when a container stops. Applications written for a server that was rarely restarted often have no handling for this at all: a queue worker mid-job simply loses it.
Handle the termination signal, stop accepting new work, finish what is in flight, and exit. Make sure the grace period is long enough for your slowest reasonable request.
Scanners see everything
This one is organizational rather than technical. Once the application is an image, every vulnerability in the base layer becomes visible to your security team on a dashboard, continuously. If the PHP version is end of life, that list grows every month and never shrinks.
Teams frequently respond by maintaining an exception list, which works until the list is long enough that nobody reads it. Running a supported runtime with backported fixes is the only approach that keeps the dashboard meaningful.
Sequencing that works
Externalize state first, on the old infrastructure, where you can verify each change independently. Then configuration. Then scheduled work. Containerize last, once the application no longer depends on anything a container will not give it.
Teams that containerize first spend the following months debugging all of the above simultaneously, in an environment they have just started learning.