PHP-FPM on top of the official PHP image, with the webdevops entrypoint, supervisord, cron, syslog-ng and the application user. The -dev variant adds Xdebug, the Blackfire extension, Postfix and an SSH server for local development.
webdevops/php-official is deprecated: it is the same image as webdevops/php under a second name, published only for the tags 8.2 to 8.5 and their -alpine tags. Switch to webdevops/php now, see Replacing discontinued images.
| Tags | Based on |
|---|---|
8.2, 8.3, 8.4, 8.5 |
php:<version>-fpm-bookworm (Debian 12) |
8.6 |
php:8.6-fpm-trixie (Debian 13) |
8.2-alpine, 8.3-alpine, 8.4-alpine, 8.5-alpine, 8.6-alpine |
php:<version>-fpm-alpine |
Both webdevops/php and webdevops/php-dev use these tags. For the differences between the Debian and the Alpine tags, see Debian or Alpine; for what is different in PHP 8.6, see PHP 8.6.
Always use one of these tags: an image without a tag (latest) and the alpine tag are old builds from 2019 and 2020, see Known issues.
services:
php:
image: webdevops/php:8.5
volumes:
- ./:/appPHP-FPM listens on port 9000. For a web server in the same container use php-nginx or php-apache.
Started by default: php-fpm, cron, syslog. The -dev variant also starts postfix and ssh. See Customization. PHP-FPM listens on port 9000 of all IPv6 and IPv4 addresses; if the container has no IPv6, of all IPv4 addresses.
| Setting | Value |
|---|---|
memory_limit |
512M |
max_execution_time |
300 |
post_max_size, upload_max_filesize |
50M |
max_input_vars |
5000 |
date.timezone |
UTC |
display_errors |
0 |
session.upload_progress.enabled |
0 |
| OPcache | enabled, opcache.memory_consumption 256, opcache.revalidate_freq 2 |
All of these can be changed with environment variables, see PHP. For larger uploads and long requests, see Uploads and long requests; for production, see Production.
All PHP images disable session.upload_progress.enabled by default. Session upload progress lets PHP write request-controlled data into the session while a multipart upload is parsed, before application code runs. Regular file uploads ($_FILES) and sessions are not affected. To turn it back on, set php.session.upload_progress.enabled: "1".
Applications that read the upload progress from the session, using a form field named like session.upload_progress.name (default PHP_SESSION_UPLOAD_PROGRESS), need this setting turned on. That includes cancelling an upload through the session (cancel_upload). Calling ini_set() in the application does not help: it returns false and the value stays off. Progress bars that measure the upload in the browser are not affected.
All tags contain these extensions:
amqp, apcu, bcmath, bz2, calendar, ctype, curl, date, dom, excimer, exif, ffi, fileinfo, filter, ftp, gd, gettext, gmp, hash, iconv, imagick, intl, json, ldap, libxml, mbstring, memcached, mongodb, mysqli, mysqlnd, openssl, opentelemetry, pcntl, pcre, pdo, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, phar, posix, protobuf, random, readline, redis, reflection, session, shmop, simplexml, soap, sockets, sodium, spl, sqlite3, standard, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlreader, xmlwriter, xsl, yaml, Zend OPcache, zip, zlib
The tags differ in these extensions. Each column covers both tags of a PHP version, for example 8.5 and 8.5-alpine; "Debian only" marks an extension that only the Debian tag contains.
| Extension | 8.2 |
8.3 |
8.4 |
8.5 |
8.6 |
|---|---|---|---|---|---|
lexbor (new in PHP 8.5) |
– | – | – | ✓ | ✓ |
uri (new in PHP 8.5) |
– | – | – | ✓ | ✓ |
imap (moved to PECL in PHP 8.4) |
✓ | ✓ | – | – | – |
vips (not built for PHP 8.6) |
✓ | ✓ | ✓ | ✓ | – |
xmlrpc (not built for PHP 8.6) |
✓ | ✓ | ✓ | ✓ | – |
| ionCube Loader (skipped on Alpine, not installed from PHP 8.6 on) | Debian only | Debian only | Debian only | Debian only | – |
PHP loads the extensions in the CLI and in PHP-FPM of php, php-nginx, php-apache and their -dev variants.
The -dev images also contain Xdebug, which is loaded by default, and the Blackfire PHP extension, which is not; PHP_DEBUGGER switches between them, see Development variant.
Disable extensions you do not need with PHP_DISMOD, for example PHP_DISMOD: redis,apcu.
docker-php-ext-install from the official PHP image still works for extensions that come with PHP's source code, for example dba. On Alpine it installs the build tools it needs and removes them again.
FROM webdevops/php:8.5
RUN docker-php-ext-install dbaFor extensions from PECL, use PIE. It does not have to stay in the image; mount it for the RUN that needs it. PIE enables the extension for PHP-FPM and the PHP CLI. The Debian images contain the build tools:
FROM webdevops/php:8.5
RUN --mount=type=bind,from=ghcr.io/php/pie:bin,source=/pie,target=/usr/local/bin/pie \
pie install pecl/pcovOn Alpine, install the build tools ($PHPIZE_DEPS) in the same RUN and remove them afterwards:
FROM webdevops/php:8.5-alpine
RUN --mount=type=bind,from=ghcr.io/php/pie:bin,source=/pie,target=/usr/local/bin/pie \
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
&& pie install pecl/pcov \
&& apk del .build-depsComposer 2 is installed as composer2, Composer 1 as composer1. composer links to one of them: Composer 2 by default, Composer 1 with COMPOSER_VERSION: "1".
COMPOSER_VERSION switches the link when a container starts, not during docker build. In a Dockerfile, composer is always Composer 2; call composer1 or composer2 directly:
FROM webdevops/php:8.5
COPY . /app
RUN cd /app && composer2 install --no-interactionEvery PHP version comes as a Debian tag (8.5) and an Alpine tag (8.5-alpine). This applies to all php-* images. The differences:
| Topic | Debian | Alpine |
|---|---|---|
| Base image | php:<version>-fpm-bookworm (Debian 12); PHP 8.6: php:8.6-fpm-trixie (Debian 13) |
php:<version>-fpm-alpine |
Download size of webdevops/php:8.5 |
about 430 MB | about 170 MB |
| ionCube Loader | included up to PHP 8.5 | not included |
imap extension |
8.2 and 8.3 only |
8.2-alpine and 8.3-alpine only |
| Build tools for extensions | included | installed by docker-php-ext-install; for PIE install $PHPIZE_DEPS |
| Locales | several hundred, for example de_DE.utf8 |
none |
| Installing packages | apt-install, from the Debian components main, contrib and non-free |
apk-install |
docker-cronjob |
adds the lines to /etc/cron.d/webdevops-docker; jobs run with PATH=/usr/bin:/bin |
adds each line without its user to /etc/crontabs/<user>; jobs run with the PATH of the container |
docker-image-cleanup |
works | works |
Apache index files in php-apache |
index.html, index.cgi, index.pl, index.php, index.xhtml, index.htm come before WEB_DOCUMENT_INDEX |
index.html comes before WEB_DOCUMENT_INDEX |
mail() without Postfix |
fails: there is no sendmail command |
fails: BusyBox sendmail finds no mail server |
The 8.6 and 8.6-alpine tags are built on PHP 8.6. Compared with PHP 8.5:
- Debian 13: The Debian tag
8.6is based on Debian 13 (trixie) instead of Debian 12, because GD in PHP 8.6 needs a newer libavif than Debian 12 provides. Package names differ between the two releases, for examplelibzip5instead oflibzip4, andapt-add-repositorydoes not work, see Known issues. - Thread safe (ZTS): The official PHP 8.6 images, and therefore all
8.6tags, are built thread safe. Extensions that you compile yourself with PIE ordocker-php-ext-installare built to match. max_execution_timecounts waiting: In thread-safe PHP, the limit ofPHP_MAX_EXECUTION_TIME(max_execution_time) counts the elapsed time, including time spent waiting, for example insleep(), for an HTTP response or for a command started withexec(); PHP stops the script with the fatal error once the call returns. In PHP 8.5 and older, only the time PHP itself runs counts. RaisePHP_MAX_EXECUTION_TIMEif your requests wait longer than its default of 300 seconds.- No
pecl: The official PHP 8.6 images no longer containpeclandpear. Install extensions with PIE, see Installing more extensions. - No
vipsandxmlrpc: Both extensions are abandoned upstream and do not build against PHP 8.6.- Instead of
vips, usejcupitt/vips2.x, which calls libvips through FFI. libvips and theffiextension are part of the images. By default PHP allows FFI only on the command line and in preloaded scripts; to use it in PHP-FPM, setphp.ffi.enable: "true". - Instead of
xmlrpc, use a userland library such asphpxmlrpc/phpxmlrpc.
- Instead of
- No ionCube Loader: The PHP 8.6 images and later do not contain the ionCube Loader, also once ionCube supports these PHP versions. Its loader for thread-safe PHP does not load in the official images, which are built without Zend signals; applications that need ionCube stay on PHP 8.5.
- Healthcheck: The
8.6tags rundocker-healthcheckas theirHEALTHCHECK, so Docker reports a container asunhealthywhen a service such as PHP-FPM or Postfix failed, see Healthcheck. - Development images: Xdebug is a 3.6 pre-release.
- Unreleased extension versions:
apcu,excimer,memcached,redisandyamlhave no release that supports PHP 8.6 yet and are built from their development branches;amqpandprotobufare built with fixes that are not released yet.
services:
php:
image: webdevops/php:8.6
environment:
php.ffi.enable: "true"Use the images without -dev in production. The -dev images load Xdebug and start Postfix and an SSH server, and php-dev sets the password dev for root and application.
Check these defaults for your application:
- PHP-FPM processes:
pm.max_childrenis5(FPM_PM_MAX_CHILDREN). PHP-FPM handles at most five requests at the same time; further requests wait. When that happens, PHP-FPM logsserver reached pm.max_children setting (5), consider raising itto the container log, or to the file ofLOG_STDERR. Raise the value if the container has memory to spare; each process can use up tomemory_limit(512M). If the log showsseems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), PHP-FPM starts processes too slowly for the load; raiseFPM_PM_START_SERVERSand the spare server settings, see PHP-FPM. - Code in the image: if your Dockerfile copies the application code into the image, set
PHP_OPCACHE_VALIDATE_TIMESTAMPS: "0". PHP then no longer checks the files for changes; a changed file takes effect only after PHP-FPM restarts. Do not use it with code mounted from the host. - Errors:
display_errorsis0(PHP_DISPLAY_ERRORS), so error messages are not shown to visitors. Keep it that way. - Uploads and long requests: the limits are in Uploads and long requests.
services:
app:
build: .
ports:
- "8080:80"
environment:
FPM_PM_MAX_CHILDREN: "20"
PHP_OPCACHE_VALIDATE_TIMESTAMPS: "0"Check the values in the running container. php-fpm -tt prints the PHP-FPM configuration. php-fpm -i prints the PHP settings that PHP-FPM uses; php -i shows the values of the PHP CLI, which differ, for example max_execution_time is 0 there.
docker compose exec app php-fpm -tt
docker compose exec app php-fpm -iPHP's mail() passes each message to /usr/sbin/sendmail.
In the images without -dev, Postfix is not running and mail() returns false. The Debian images have no /usr/sbin/sendmail; in the Alpine images it is BusyBox's sendmail, which finds no mail server on 127.0.0.1. To send mail with mail(), enable Postfix in your Dockerfile and set POSTFIX_RELAYHOST to a mail server that accepts mail from the container. There is no variable for a login at the relay host.
FROM webdevops/php-nginx:8.5
RUN docker-service enable postfixservices:
app:
build: .
environment:
POSTFIX_RELAYHOST: "[mail.example.com]:25"The -dev images start Postfix. It has no relay host and delivers each message directly to the recipient's mail server.
Postfix does not use SMTPUTF8 (smtputf8_enable = no), so a message with UTF-8 in its headers, for example in the subject, also reaches a relay host or mail catcher that does not offer it.
Warning
Without a relay host, Postfix in a development container tries to deliver mail to real recipients. Send it to a mail catcher such as Mailpit instead.
services:
app:
image: webdevops/php-nginx-dev:8.5
ports:
- "8080:80"
volumes:
- ./:/app
environment:
POSTFIX_RELAYHOST: "[mailpit]:1025"
mailpit:
image: axllent/mailpit
ports:
- "8025:8025"Mail from PHP-FPM and from the PHP CLI then shows up in Mailpit at http://localhost:8025.
php-dev is built on php and changes the following:
- Xdebug is loaded by default (
xdebug.mode=debug,xdebug.start_with_request=trigger,xdebug.client_port=9003), see Xdebug with an IDE.PHP_DEBUGGERswitches to Blackfire or turns both off, see Development images. With Blackfire and its server credentials, the Blackfire agent runs in the container too. opcache.revalidate_freqis0, so changed files are picked up immediately.- Postfix and an SSH server are started. Postfix sends mail to real recipients unless you set a relay host, see Mail.
rootandapplicationhave the passworddev. Use the-devimages for local development only.
Xdebug connects to your IDE on port 9003. Set php.xdebug.client_host to the host the IDE runs on. host.docker.internal is the Docker host; Docker Desktop provides the name, on Linux add it with extra_hosts:
services:
app:
image: webdevops/php-nginx-dev:8.5
ports:
- "8080:80"
volumes:
- ./:/app
environment:
php.xdebug.client_host: host.docker.internal
extra_hosts:
- "host.docker.internal:host-gateway"XDEBUG_CLIENT_HOST: host.docker.internal has the same effect.
-
Start a debug session: Xdebug only connects when the request carries the trigger
XDEBUG_SESSION. In the browser, add?XDEBUG_SESSION=1to the URL, or set the cookieXDEBUG_SESSIONas browser extensions for Xdebug do. On the command line, set the environment variable:docker compose exec -u application -e XDEBUG_SESSION=1 app php bin/console app:import -
Path mapping: Xdebug reports the paths inside the container, for example
/app/public/index.php. In the IDE, map your project directory to/app. -
Client discovery:
xdebug.discover_client_hostis1. For browser requests Xdebug first connects to the address in theX-Forwarded-Forheader or, without it, to the address the request came from. Only if that fails does it usexdebug.client_host. On the command line there is no such address, and Xdebug always usesxdebug.client_host. That is why the example sets it.