Skip to content

Build the 8.3–8.5 CLI images on the official PHP images - #11

Merged
michaelaguiar merged 4 commits into
mainfrom
cli-official-php
Oct 21, 2026
Merged

michaelaguiar merged 4 commits into
mainfrom
cli-official-php

Conversation

@michaelaguiar

@michaelaguiar michaelaguiar commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

The 8.3, 8.4 and 8.5 CLI images used Alpine's PHP packages. Alpine's stable releases rarely move to a new PHP patch release, so the published images were well behind:

Before (Alpine package) After (official php:X-cli-alpine)
8.3-cli 8.3.19 (Alpine 3.21) 8.3.36
8.4-cli 8.4.16 (Alpine 3.22) 8.4.27
8.5-cli 8.5.11 (alpine:edge) 8.5.12

All three were still exposed to CVE-2026-109618/109619. The official images follow php.net releases, and the FrankenPHP images are built on the thread-safe (ZTS) variant of the same images. CLI and web containers now get PHP from the same source and build recipe, currently at the same patch versions.

Kept the same as before:

  • max_execution_time = 0, php.ini-production defaults and date.timezone=UTC;
  • the MySQL default socket, /run/mysqld/mysqld.sock, for mysqli and pdo_mysql. The official images leave it empty, which falls back to /tmp/mysql.sock;
  • /usr/bin/php and /usr/bin/phpXY, which are symlinks now, so existing scripts keep working;
  • 8.4's extension set and user.

8.3 and 8.5 now match 8.4 apart from the PHP version. They used to run as root with a large extension set; now they have:

  • uid 1000 (appuser, group 0);
  • a 512M memory limit;
  • 8.4's minimal extension set, which adds intl and drops gd, exif, imagick, mysqli, redis, igbinary, msgpack and sockets. Those belong in a derived image, as in 8.4/cli/Dockerfile.wordpress.

Anything that relied on those extensions in 8.3-cli or 8.5-cli, or on running as root, needs a derived image.

What changed:

  • Extensions are now installed with install-php-extensions, like the FrankenPHP images. 8.4/cli/Dockerfile.wordpress now installs the same list as frankenphp/Dockerfile.wordpress.
  • The README's CLI description now describes the three images as identical.
  • Migration note: PHP's ini directory moves from /etc/php8X/ to /usr/local/etc/php/. A volume mounting a custom ini into /etc/php84/conf.d/ would silently stop applying, so mount into /usr/local/etc/php/conf.d/ instead. A derived image that runs apk add php84-… must switch to install-php-extensions ….
  • The workflow comment notes that CLI arm64 builds now compile extensions under QEMU.

7.4, 8.0 and 8.1 are unchanged. They're end-of-life, and the official images for them don't get fixes either.

Trade-offs

  • Image size.

    Image before → after Compressed before → after
    8.3 90 → 211 MB 22 → 55 MB
    8.4 71 → 219 MB 17 → 59 MB
    8.5 120 → 247 MB 29 → 62 MB
    • Compressed is about what a server downloads on pull.
    • The growth is mostly the official base image itself (167 MB for 8.4), which includes the PHP source and headers for building extensions, plus the full ICU locale data for intl.
  • Build time and pecl. Extensions are compiled during the build rather than installed as Alpine packages (pecl ones only in derived images such as the wordpress CLI image). arm64 builds run under QEMU, so they'll be slower, and a pecl outage can fail a build. FrankenPHP wordpress builds already work this way.

Benchmark

All runs were on the same host (amd64), pinned to one CPU core, with medians of 5 runs (bench.php) or 3 runs (others). Each pair was run twice, interleaved. bench.php and micro_bench.php come from php-src. Startup is one php -v call.

PHP bench.php micro_bench.php Startup Peak RSS
8.3 old 8.3.19 0.232 s 1.19 s 10.4 ms 26.9 MB
8.3 new 8.3.36 0.154 s 0.72 s 8.0 ms 23.8 MB
8.4 old 8.4.16 0.233 s 1.17 s 8.6 ms 25.6 MB
8.4 new 8.4.27 0.155 s 0.69 s 8.0 ms 25.7 MB
8.5 old 8.5.11 0.157 s 0.73 s 13.4 ms 32.3 MB
8.5 new 8.5.12 0.153 s 0.68 s 9.3 ms 28.4 MB
  • CPU-bound work takes about a third less time on 8.3 and 8.4 (bench.php 33%, micro_bench.php 40–41%), and slightly less on 8.5. The old Alpine 3.21/3.22 builds were much slower than both the alpine:edge and official builds. Alpine doesn't show its compiler flags, so I couldn't confirm why.
  • Startup is the same or faster: 8.3 and 8.5 load fewer extensions now.
  • Peak memory is the same for 8.4, and about 3–4 MB lower for 8.3 and 8.5.

Test plan

  • All four images build locally (amd64), including 8.4-cli-wordpress built against the new 8.4-cli.
  • The new 8.4 image matches the published one: the same modules (plus pdo_sqlite/sqlite3, which the official image builds in), uid, ini values, timezone, MySQL socket defaults and /usr/bin/php* paths.
  • 8.3 and 8.5 match 8.4: the same uid, ini values and socket, /app writable, and the same modules apart from 8.5's built-in lexbor and uri.
  • igbinary data written by 8.4-frankenphp-wordpress is read correctly by the new 8.4-cli-wordpress.
  • In 8.4-cli-wordpress:
    • imagick and gd work;
    • /app is writable as uid 1000;
    • wp --info runs on PHP 8.4.27.
  • After merge: CI builds the CLI tags. I'll check each one has the patched PHP and both amd64 and arm64, and note how long the arm64 builds take.

8.4-cli-wordpress isn't built by CI today, so the change to its Dockerfile is only tested locally.

The cli images used Alpine's PHP packages, which on stable branches sit
on one patch release for months: 8.3-cli was on 8.3.19 and 8.4-cli on
8.4.16, both still exposed to CVE-2026-109618/109619, and 8.5-cli needed
alpine:edge. The official php:X-cli-alpine images track php.net and are
the same PHP build the frankenphp images use.

Each image keeps its extension set, user, ini settings, timezone and the
/usr/bin/php and /usr/bin/phpXY paths. Extensions now come from
install-php-extensions, as in the frankenphp images, so the 8.4 wordpress
cli image installs the same list as frankenphp/Dockerfile.wordpress. The
unused php-cgi and phpdbg binaries are removed.
The Alpine-package images defaulted mysqli and pdo_mysql to
/run/mysqld/mysqld.sock; the official images leave both empty, so a
"localhost" connection fell back to /tmp/mysql.sock and failed where the
MariaDB socket is mounted at /run/mysqld. Set both in 99-cli.ini.

Removing php-cgi/phpdbg deleted files from the base image's layer, which
saves nothing in image or pull size, so drop it. Correct the header
comment (the frankenphp images use the ZTS variant of the same images,
not the same build) and the README (images rebuild only on a Dockerfile
change or a manual run; 8.3/8.5 don't have intl; ini path).
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 1 (single round)

I had a reviewer with fresh context check this PR with code-review at high effort. It rebuilt all four images and compared them with the published images, the official bases and 8.4-frankenphp-wordpress.

Confirmed holds

  • The module lists are identical to the published images, plus pdo_sqlite/sqlite3.
  • Users, memory_limit, max_execution_time, UTC, the production defaults and the CA bundle all match.
  • /usr/bin/php* works, and the Redis serializers and compression match.
  • igbinary data written by 8.4-frankenphp-wordpress reads correctly in the new 8.4-cli-wordpress.
  • docker-php-entrypoint only changes the case where the first argument starts with -.
  • The floating mlocati/php-extension-installer:2 matches the repo's existing composer:2.
  • The skill's claims of dropped opcache, an iconv regression and new msgpack/sockets were checked and are false.

Findings

  • P2: the MySQL default socket was lost (fixed in 416141c). The old images defaulted mysqli/pdo_mysql to /run/mysqld/mysqld.sock, but the official images leave it empty, which falls back to /tmp/mysql.sock. Both are now set in 99-cli.ini, and I checked them on all four images.
  • P2: nothing rebuilds the images when a new PHP patch ships (README fixed in 416141c; the CI change is waiting on Mike).
    • The README said the images get patches "as soon as" the official images do. It now says a rebuild picks up the latest patch, and that builds only run when a Dockerfile changes or the workflow is run by hand.
    • A scheduled rebuild would rebuild every image, FrankenPHP included, and change when new images reach servers. That's Mike's decision, so it isn't in this PR.
  • P3: the size figures understated the growth (fixed in the PR body). I replaced the container-disk numbers with image and compressed sizes. Removing php-cgi/phpdbg deleted files from the base image's layer, which saves nothing in image or pull size, so 416141c drops it.
  • P3: the comment said CLI and FrankenPHP run the "same PHP build" (fixed in 416141c). FrankenPHP uses the thread-safe (ZTS) variant of the same images. The comment and PR body now say "same source and build recipe".
  • P3: the README implied 8.3/8.5 have intl (fixed in 416141c). The README now lists their actual extension set.
  • P3: the old ini path and Alpine package names no longer apply (documented). I added a migration note to the PR body.
  • P3: Dockerfile.wordpress fails against the old 8.4-cli base (declined). This file has never been built by CI, and it's normal to build it after its base is published. After merge the base has install-php-extensions.
  • P3: arm64 builds are slower under QEMU (declined, known trade-off). The new workflow comment already says so, and the post-merge run will measure it.

@michaelaguiar
michaelaguiar marked this pull request as ready for review October 21, 2026 21:34
8.4-cli was reworked into the tiered design (minimal extensions,
unprivileged appuser, 512M memory limit) but 8.3 and 8.5 kept the older
root, all-extensions layout. The three are now identical apart from the
PHP version. 8.3/8.5 drop gd, exif, imagick, mysqli, redis, igbinary,
msgpack and sockets (they belong in a derived image, as in
8.4/cli/Dockerfile.wordpress), gain intl, and run as uid 1000.
The cli images have no ENV block; say how to override their settings.
@michaelaguiar

michaelaguiar commented Oct 21, 2026 •

Copy link
Copy Markdown
Member Author

Review round 2 (narrow: 6132bc6, 8.3/8.5 matched to 8.4)

Mike decided that the 8.3 and 8.5 CLI images should be identical to 8.4 apart from the PHP version. In 6132bc6 they now run as uid 1000 with 512M and 8.4's minimal extensions. They gain intl and drop gd/exif/imagick/mysqli/redis/igbinary/msgpack/sockets.

A reviewer with fresh context found no defects in that commit.

Confirmed holds

  • The 8.3 and 8.5 Dockerfiles differ from 8.4 only in the FROM line and the phpXY symlink and its comment.
  • Fresh rebuilds load without warnings and run as 1000:0.
  • intl works, and the ini values and MySQL socket match 8.4.
  • /app is writable, and the /usr/bin/php* symlinks resolve.
  • The PR body's list of dropped extensions and its size figures are accurate.

Fixed: the reviewer noted an inaccuracy from before this PR. The README said every image takes PHP_* environment variables, but the CLI images have no ENV block. ef1cb7e limits that sentence to the FrankenPHP images and says how to override CLI settings.

@michaelaguiar
michaelaguiar merged commit 7b9353b into main Oct 21, 2026
2 checks passed
@michaelaguiar michaelaguiar mentioned this pull request Oct 21, 2026
2 of 3 tasks
@michaelaguiar
michaelaguiar deleted the cli-official-php branch October 21, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant