Back to blog
PHPDockerLaravel

PHP 8.6 switches to ZTS in official Docker images

Moving to php:8.6-fpm is no longer just a version update: it also changes how PHP is built.

By Isma5 min read

The change is inside your base image

If your Laravel Dockerfile starts from php:8.6-fpm, this is worth checking before treating it as a routine version bump. Official PHP 8.6 images are being built with ZTS enabled by default, including the FPM variant. This is not a PHP setting you can toggle in php.ini; it is part of how the interpreter was compiled.

ZTS stands for Zend Thread Safety. In practical terms, PHP has been built with thread-safety support, and that becomes a property of the binary running your application. The official Dockerfile for the FPM image explicitly includes --enable-zts alongside --enable-fpm.

A Laravel application using only common extensions installed from the image may not show any immediate difference. I still would not classify this as a plain base-image update. If the container includes native binaries, compiled extensions, or software distributed outside the usual PHP ecosystem, the build mode matters.

Check the image you will actually deploy

You do not need to guess whether an image uses ZTS from its tag. Check it inside the exact container you plan to build and deploy. PHP exposes this information through php -i and through the PHP_ZTS constant.

FROM php:8.6-fpm
 
RUN php -i | grep 'Thread Safety' \
    && php -r 'var_dump(PHP_ZTS);' \
    && php -m

The php -i output should report that thread safety is enabled, and PHP_ZTS should evaluate to true. This does not fix compatibility problems, but it prevents development, CI, and production from quietly running different kinds of PHP binaries. It also leaves a useful trace in build logs when this decision needs to be reviewed later.

I would also run the Laravel test suite against the final image, not against a different local PHP installation. That includes integration tests that load extensions, connect to external services, or enable observability tooling. The goal is not to prove that ZTS is faster or slower, but to find dependencies that assumed a different PHP build.

Native extensions are the sensitive part

PHP extensions compiled from source are not interchangeable across every PHP version, architecture, and interpreter configuration. If you build an internal extension, build it from the same PHP 8.6 base image you will use in production. Building it in an older image and copying the result into php:8.6-fpm is exactly the shortcut worth reviewing now.

The same applies to private repositories, precompiled artifacts, and packages supplied by third parties. There is no need to assume they will fail, but you should confirm that the provider supports PHP 8.6 built with ZTS. The check should cover installation, loading the extension, and the real application path that depends on it.

APM agents deserve the same level of attention. Many of them integrate as native extensions or depend on components loaded by PHP during startup. Before shipping the new image, check the vendor compatibility matrix for PHP 8.6 and ZTS, then verify that telemetry still arrives from an environment matching production.

The fine print matters

ZTS does not automatically make a Laravel application parallel, and it does not make one FPM process handle multiple requests inside the same interpreter. FPM keeps its own process model, and its configuration does not change simply because PHP was compiled with ZTS. This change also does not replace a review of memory limits, FPM workers, or container replicas.

It is not a compatibility guarantee for every extension either. PHP documents, for example, that chroot() is unavailable in interpreters compiled with ZTS. That is one specific case, but it makes the broader point: a build mode can affect available features and assumptions made by software interacting with the runtime.

I would not claim performance gains or losses without reproducible measurements for a specific workload. A web application has too many variables across PHP, FPM, OPcache, the database, the network, and application code. The useful decision is simpler: treat the move to php:8.6-fpm as both a PHP upgrade and a build-mode change.

A sensible Laravel migration path

First, create a test branch using the PHP 8.6 tag you intend to deploy. Then install every extension and agent exactly as production does, run the test suite, and start the web and queue processes. Finally, inspect startup logs from PHP, FPM, and your observability integrations before promoting the image.

If several projects share a derived base image, put the ZTS check and extension setup there. That prevents every repository from handling the transition differently or copying extensions built for a different environment. Recording the decision next to the Dockerfile will be more useful than leaving it buried in an upgrade ticket.

The conclusion is not that PHP 8.6 should be avoided. The conclusion is that FROM php:8.6-fpm no longer means only “a newer PHP version”; it also introduces a different build mode from the familiar NTS images. Verifying that in your build and testing what you load natively is cheaper than discovering it after deployment.


Source: https://discourse.thephp.foundation/t/php-dev-docker-images-for-8-6-now-default-to-zts/6479

Official Dockerfile: https://github.com/docker-library/php/blob/master/8.6/bookworm/fpm/Dockerfile

Official PHP documentation: https://www.php.net/manual/en/function.chroot.php

Newsletter

What I learn coding with AI, every two weeks in your inbox.

Real numbers, mistakes included. No spam, unsubscribe in one click.

No spam, unsubscribe in one click. I only use your email to send you this and the newsletter. More in the privacy policy.