From 4b4df9baeae1ae50cada2184e9b68ddabc32aa0b Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 22 Oct 2026 11:03:03 +0530 Subject: [PATCH 1/5] fix(php): stop installing opcache as a shared extension on 8.5 Opcache is always compiled into PHP 8.5, so docker-php-ext-install opcache fails (cp: cannot stat 'modules/*'). The ;-chained RUN hid the failure, and the image still loads Zend OPcache, so dropping the step changes nothing in the image. --- php/8.5/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/8.5/Dockerfile b/php/8.5/Dockerfile index 816612d..39e023d 100644 --- a/php/8.5/Dockerfile +++ b/php/8.5/Dockerfile @@ -48,7 +48,7 @@ RUN pecl install memcached; \ docker-php-ext-install gd; \ docker-php-ext-install mysqli; \ docker-php-ext-install pdo_mysql; \ - docker-php-ext-install opcache; \ + # opcache is built into PHP 8.5, so docker-php-ext-install opcache would fail docker-php-ext-install soap; \ docker-php-ext-install intl; \ docker-php-ext-install zip; \ From e9eb20eb40eb78ef8623c5fd8d4cf920c6025379 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 22 Oct 2026 11:03:13 +0530 Subject: [PATCH 2/5] fix(php): fail the build when the wp-cli download fails curl -O without -f saved an HTTP error page as wp-cli.phar, so a failed download produced an image with a broken wp. --- php/8.1/Dockerfile | 5 ++--- php/8.2/Dockerfile | 5 ++--- php/8.3/Dockerfile | 5 ++--- php/8.4/Dockerfile | 5 ++--- php/8.5/Dockerfile | 5 ++--- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/php/8.1/Dockerfile b/php/8.1/Dockerfile index 9acee4f..916b79c 100644 --- a/php/8.1/Dockerfile +++ b/php/8.1/Dockerfile @@ -87,9 +87,8 @@ RUN curl -sSL "https://getcomposer.org/installer" | php \ && mv composer.phar /usr/local/bin/composer # Install wp-cli -RUN curl -O "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ - && chmod +x wp-cli.phar \ - && mv wp-cli.phar /usr/local/bin/wp +RUN curl -fsSLo /usr/local/bin/wp "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ + && chmod +x /usr/local/bin/wp # Setup a config file RUN mkdir -p /etc/wp-cli diff --git a/php/8.2/Dockerfile b/php/8.2/Dockerfile index 8505426..33299dd 100644 --- a/php/8.2/Dockerfile +++ b/php/8.2/Dockerfile @@ -85,9 +85,8 @@ RUN curl -sSL "https://getcomposer.org/installer" | php \ && mv composer.phar /usr/local/bin/composer # Install wp-cli -RUN curl -O "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ - && chmod +x wp-cli.phar \ - && mv wp-cli.phar /usr/local/bin/wp +RUN curl -fsSLo /usr/local/bin/wp "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ + && chmod +x /usr/local/bin/wp # Setup a config file RUN mkdir -p /etc/wp-cli diff --git a/php/8.3/Dockerfile b/php/8.3/Dockerfile index 504049c..8875f17 100644 --- a/php/8.3/Dockerfile +++ b/php/8.3/Dockerfile @@ -103,9 +103,8 @@ RUN curl -sSL "https://getcomposer.org/installer" | php \ && mv composer.phar /usr/local/bin/composer # Install wp-cli -RUN curl -O "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ - && chmod +x wp-cli.phar \ - && mv wp-cli.phar /usr/local/bin/wp +RUN curl -fsSLo /usr/local/bin/wp "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ + && chmod +x /usr/local/bin/wp # Setup a config file RUN mkdir -p /etc/wp-cli diff --git a/php/8.4/Dockerfile b/php/8.4/Dockerfile index 604fe3f..6ba94e8 100644 --- a/php/8.4/Dockerfile +++ b/php/8.4/Dockerfile @@ -107,9 +107,8 @@ RUN curl -sSL "https://getcomposer.org/installer" | php \ && mv composer.phar /usr/local/bin/composer # Install wp-cli -RUN curl -O "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ - && chmod +x wp-cli.phar \ - && mv wp-cli.phar /usr/local/bin/wp +RUN curl -fsSLo /usr/local/bin/wp "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ + && chmod +x /usr/local/bin/wp # Setup a config file RUN mkdir -p /etc/wp-cli diff --git a/php/8.5/Dockerfile b/php/8.5/Dockerfile index 39e023d..bb52dbd 100644 --- a/php/8.5/Dockerfile +++ b/php/8.5/Dockerfile @@ -105,9 +105,8 @@ RUN curl -sSL "https://getcomposer.org/installer" | php \ && mv composer.phar /usr/local/bin/composer # Install wp-cli -RUN curl -O "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ - && chmod +x wp-cli.phar \ - && mv wp-cli.phar /usr/local/bin/wp +RUN curl -fsSLo /usr/local/bin/wp "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" \ + && chmod +x /usr/local/bin/wp # Setup a config file RUN mkdir -p /etc/wp-cli From 3c0f9c9add1157df6178c079d9d4a14af91c45b7 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 22 Oct 2026 11:18:01 +0530 Subject: [PATCH 3/5] build(php): install extensions with PIE and fail the build on errors The pecl install steps were chained with ;, so when pecl.php.net was down a build still succeeded, just without memcached, redis, apcu and the rest, and PHP then warned about the missing libraries on every start. For the 8.1 to 8.5 images (the ones CI builds and publishes): - Install imagick, memcached, redis, apcu, mcrypt and timezonedb with PIE 1.5.2 (checked against its SHA-256) from Packagist/GitHub. Versions are pinned to what the current images ship; timezonedb stays unpinned because it only exists to ship newer tz data than PHP bundles. The resolved commits are printed to the build log. - Build imap (8.4, 8.5) and gmagick (8.1 to 8.4), which aren't on Packagist, from SHA-256-pinned GitHub tarballs of their pecl releases. - Run the extension step under set -eu so any failing step fails the build. - Add a final check that fails the build on PHP startup warnings or errors, a failing php-fpm -t, wp or composer, or a module missing from the expected list. - 8.3 and 8.5 now get the imagick 3.8.1 release instead of an unversioned git master build. Extensions are still enabled with docker-php-ext-enable and the existing ini lines, so conf.d is unchanged. --- php/8.1/Dockerfile | 56 +++++++++++++++++++++++++++----- php/8.2/Dockerfile | 56 +++++++++++++++++++++++++++----- php/8.3/Dockerfile | 76 +++++++++++++++++++++++++++---------------- php/8.4/Dockerfile | 81 ++++++++++++++++++++++++++++++---------------- php/8.5/Dockerfile | 76 +++++++++++++++++++++++++++---------------- 5 files changed, 248 insertions(+), 97 deletions(-) diff --git a/php/8.1/Dockerfile b/php/8.1/Dockerfile index 916b79c..629fbbf 100644 --- a/php/8.1/Dockerfile +++ b/php/8.1/Dockerfile @@ -37,14 +37,35 @@ RUN curl -fsSL https://packages.sury.org/php/README.txt | bash && \ apt-get update && \ apt-get install -y libc-client-dev -RUN pecl install imagick; \ - pecl install memcached; \ - pecl install redis; \ - pecl install apcu; \ - # https://github.com/php/pecl-encryption-mcrypt/issues/7#issuecomment-1050994596 - pecl install -n mcrypt; \ - pecl install gmagick-2.0.6RC1; \ - pecl install timezonedb; \ +# Extensions are built with PIE from Packagist/GitHub (not pecl.php.net); docker-php-ext-enable below enables them. +# CI passes its GITHUB_TOKEN as the optional `github_token` BuildKit secret for PIE's GitHub downloads; it never lands in a layer. +RUN --mount=type=secret,id=github_token \ + set -eu; \ + if [ -s /run/secrets/github_token ]; then \ + COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"$(cat /run/secrets/github_token)\"}}"; \ + export COMPOSER_AUTH; \ + fi; \ + set -x; \ + curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ + echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ + chmod +x /usr/local/bin/pie; \ + pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ + pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ + pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \ + pie install --no-interaction --skip-enable-extension apcu/apcu:5.1.28; \ + pie install --no-interaction --skip-enable-extension pecl/mcrypt:1.0.9; \ + # timezonedb stays unpinned: it only exists to ship newer tz data than PHP bundles, so it takes the latest release + pie install --no-interaction --skip-enable-extension pecl/timezonedb; \ + # Record the exact commits PIE installed in the build log + php -r 'foreach (glob("/root/.pie/*/pie.lock") as $f) foreach (json_decode(file_get_contents($f), true)["packages"] as $p) echo "PIE installed ", $p["name"], " ", $p["version"], " ", $p["dist"]["reference"] ?? $p["source"]["reference"] ?? "?", "\n";'; \ + rm -rf /usr/local/bin/pie /root/.pie /root/.composer; \ + # gmagick isn't on Packagist: build the source of its pecl 2.0.6RC1 release + mkdir /tmp/gmagick; \ + curl -fsSL -o /tmp/gmagick.tar.gz https://github.com/vitoc/gmagick/archive/55423eec7715e89ad63334b35debf582b9566756.tar.gz; \ + echo "01fd8f0b0c7e92cd73b9165fa3ea4b247beb35bad8f6dda85d65e960607e97b5 /tmp/gmagick.tar.gz" | sha256sum -c -; \ + tar -xzf /tmp/gmagick.tar.gz -C /tmp/gmagick --strip-components=1; \ + ( cd /tmp/gmagick && phpize && ./configure && make -j"$(nproc)" && make install ); \ + rm -rf /tmp/gmagick /tmp/gmagick.tar.gz; \ docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \ docker-php-ext-configure zip; \ docker-php-ext-install gd; \ @@ -125,6 +146,25 @@ COPY docker-entrypoint.sh /usr/local/bin/ COPY newrelic.ini /usr/local/etc/php/conf.d/newrelic.ini COPY newrelic.ini /data/newrelic.ini +# Fail the build on a PHP startup warning or error, a broken php-fpm config, wp or composer, or a missing module. +# The list is the previous image's full `php -m`, so it also catches a module dropped from PHP itself. +RUN set -eu; \ + out="$(php -v 2>&1 && php -m 2>&1)"; \ + if printf '%s\n' "$out" | grep -qiE 'warning|error|notice|unable to'; then \ + echo "Build check failed: PHP printed these startup warnings or errors:" >&2; \ + printf '%s\n' "$out" | grep -iE 'warning|error|notice|unable to' >&2; \ + exit 1; \ + fi; \ + php-fpm -t; \ + wp --allow-root --version; \ + COMPOSER_ALLOW_SUPERUSER=1 composer --version; \ + modules="$(php -m | tr '[:upper:] ' '[:lower:]_')"; \ + for m in apcu bcmath calendar core ctype curl date dom exif fileinfo filter ftp gd gmagick gmp hash iconv imagick imap intl json libxml mbstring mcrypt memcached mysqli mysqlnd newrelic openssl pcntl pcre pdo pdo_mysql pdo_sqlite phar posix readline redis reflection session shmop simplexml soap sockets sodium spl sqlite3 standard sysvsem sysvshm timezonedb tokenizer xml xmlreader xmlwriter zend_opcache zip zlib; do \ + printf '%s\n' "$modules" | grep -qx "$m" || { echo "Build check failed: PHP module $m is missing" >&2; exit 1; }; \ + done; \ + # The checks above leave root-owned logs that www-data couldn't write at runtime; don't ship them + rm -f /var/log/php/access.log /var/log/php/error.log /var/log/newrelic/php_agent.log + WORKDIR /var/www/htdocs RUN usermod -s /bin/bash www-data USER www-data diff --git a/php/8.2/Dockerfile b/php/8.2/Dockerfile index 33299dd..78dfc74 100644 --- a/php/8.2/Dockerfile +++ b/php/8.2/Dockerfile @@ -35,14 +35,35 @@ RUN curl -fsSL https://packages.sury.org/php/README.txt | bash && \ apt-get update && \ apt-get install -y libc-client-dev -RUN pecl install imagick; \ - pecl install memcached; \ - pecl install redis; \ - pecl install apcu; \ - # https://github.com/php/pecl-encryption-mcrypt/issues/7#issuecomment-1050994596 - pecl install -n mcrypt; \ - pecl install gmagick-2.0.6RC1; \ - pecl install timezonedb; \ +# Extensions are built with PIE from Packagist/GitHub (not pecl.php.net); docker-php-ext-enable below enables them. +# CI passes its GITHUB_TOKEN as the optional `github_token` BuildKit secret for PIE's GitHub downloads; it never lands in a layer. +RUN --mount=type=secret,id=github_token \ + set -eu; \ + if [ -s /run/secrets/github_token ]; then \ + COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"$(cat /run/secrets/github_token)\"}}"; \ + export COMPOSER_AUTH; \ + fi; \ + set -x; \ + curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ + echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ + chmod +x /usr/local/bin/pie; \ + pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ + pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ + pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \ + pie install --no-interaction --skip-enable-extension apcu/apcu:5.1.28; \ + pie install --no-interaction --skip-enable-extension pecl/mcrypt:1.0.9; \ + # timezonedb stays unpinned: it only exists to ship newer tz data than PHP bundles, so it takes the latest release + pie install --no-interaction --skip-enable-extension pecl/timezonedb; \ + # Record the exact commits PIE installed in the build log + php -r 'foreach (glob("/root/.pie/*/pie.lock") as $f) foreach (json_decode(file_get_contents($f), true)["packages"] as $p) echo "PIE installed ", $p["name"], " ", $p["version"], " ", $p["dist"]["reference"] ?? $p["source"]["reference"] ?? "?", "\n";'; \ + rm -rf /usr/local/bin/pie /root/.pie /root/.composer; \ + # gmagick isn't on Packagist: build the source of its pecl 2.0.6RC1 release + mkdir /tmp/gmagick; \ + curl -fsSL -o /tmp/gmagick.tar.gz https://github.com/vitoc/gmagick/archive/55423eec7715e89ad63334b35debf582b9566756.tar.gz; \ + echo "01fd8f0b0c7e92cd73b9165fa3ea4b247beb35bad8f6dda85d65e960607e97b5 /tmp/gmagick.tar.gz" | sha256sum -c -; \ + tar -xzf /tmp/gmagick.tar.gz -C /tmp/gmagick --strip-components=1; \ + ( cd /tmp/gmagick && phpize && ./configure && make -j"$(nproc)" && make install ); \ + rm -rf /tmp/gmagick /tmp/gmagick.tar.gz; \ docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \ docker-php-ext-configure zip; \ docker-php-ext-install gd; \ @@ -123,6 +144,25 @@ COPY docker-entrypoint.sh /usr/local/bin/ COPY newrelic.ini /usr/local/etc/php/conf.d/newrelic.ini COPY newrelic.ini /data/newrelic.ini +# Fail the build on a PHP startup warning or error, a broken php-fpm config, wp or composer, or a missing module. +# The list is the previous image's full `php -m`, so it also catches a module dropped from PHP itself. +RUN set -eu; \ + out="$(php -v 2>&1 && php -m 2>&1)"; \ + if printf '%s\n' "$out" | grep -qiE 'warning|error|notice|unable to'; then \ + echo "Build check failed: PHP printed these startup warnings or errors:" >&2; \ + printf '%s\n' "$out" | grep -iE 'warning|error|notice|unable to' >&2; \ + exit 1; \ + fi; \ + php-fpm -t; \ + wp --allow-root --version; \ + COMPOSER_ALLOW_SUPERUSER=1 composer --version; \ + modules="$(php -m | tr '[:upper:] ' '[:lower:]_')"; \ + for m in apcu bcmath calendar core ctype curl date dom exif fileinfo filter gd gmagick gmp hash iconv imagick imap intl json libxml mbstring mcrypt memcached mysqli mysqlnd newrelic openssl pcntl pcre pdo pdo_mysql pdo_sqlite phar posix random readline redis reflection session shmop simplexml soap sockets sodium spl sqlite3 standard sysvsem sysvshm timezonedb tokenizer xml xmlreader xmlwriter zend_opcache zip zlib; do \ + printf '%s\n' "$modules" | grep -qx "$m" || { echo "Build check failed: PHP module $m is missing" >&2; exit 1; }; \ + done; \ + # The checks above leave root-owned logs that www-data couldn't write at runtime; don't ship them + rm -f /var/log/php/access.log /var/log/php/error.log /var/log/newrelic/php_agent.log + WORKDIR /var/www/htdocs RUN usermod -s /bin/bash www-data USER www-data diff --git a/php/8.3/Dockerfile b/php/8.3/Dockerfile index 8875f17..0b2ba42 100644 --- a/php/8.3/Dockerfile +++ b/php/8.3/Dockerfile @@ -35,14 +35,35 @@ RUN curl -fsSL https://packages.sury.org/php/README.txt | bash && \ apt-get update && \ apt-get install -y libc-client-dev -# RUN pecl install imagick; \ # This is not working with PHP 8.3 -RUN pecl install memcached; \ - pecl install redis; \ - pecl install apcu; \ - # https://github.com/php/pecl-encryption-mcrypt/issues/7#issuecomment-1050994596 - pecl install -n mcrypt; \ - pecl install gmagick-2.0.6RC1; \ - pecl install timezonedb; \ +# Extensions are built with PIE from Packagist/GitHub (not pecl.php.net); docker-php-ext-enable below enables them. +# CI passes its GITHUB_TOKEN as the optional `github_token` BuildKit secret for PIE's GitHub downloads; it never lands in a layer. +RUN --mount=type=secret,id=github_token \ + set -eu; \ + if [ -s /run/secrets/github_token ]; then \ + COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"$(cat /run/secrets/github_token)\"}}"; \ + export COMPOSER_AUTH; \ + fi; \ + set -x; \ + curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ + echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ + chmod +x /usr/local/bin/pie; \ + pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ + pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ + pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \ + pie install --no-interaction --skip-enable-extension apcu/apcu:5.1.28; \ + pie install --no-interaction --skip-enable-extension pecl/mcrypt:1.0.9; \ + # timezonedb stays unpinned: it only exists to ship newer tz data than PHP bundles, so it takes the latest release + pie install --no-interaction --skip-enable-extension pecl/timezonedb; \ + # Record the exact commits PIE installed in the build log + php -r 'foreach (glob("/root/.pie/*/pie.lock") as $f) foreach (json_decode(file_get_contents($f), true)["packages"] as $p) echo "PIE installed ", $p["name"], " ", $p["version"], " ", $p["dist"]["reference"] ?? $p["source"]["reference"] ?? "?", "\n";'; \ + rm -rf /usr/local/bin/pie /root/.pie /root/.composer; \ + # gmagick isn't on Packagist: build the source of its pecl 2.0.6RC1 release + mkdir /tmp/gmagick; \ + curl -fsSL -o /tmp/gmagick.tar.gz https://github.com/vitoc/gmagick/archive/55423eec7715e89ad63334b35debf582b9566756.tar.gz; \ + echo "01fd8f0b0c7e92cd73b9165fa3ea4b247beb35bad8f6dda85d65e960607e97b5 /tmp/gmagick.tar.gz" | sha256sum -c -; \ + tar -xzf /tmp/gmagick.tar.gz -C /tmp/gmagick --strip-components=1; \ + ( cd /tmp/gmagick && phpize && ./configure && make -j"$(nproc)" && make install ); \ + rm -rf /tmp/gmagick /tmp/gmagick.tar.gz; \ docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \ docker-php-ext-configure zip; \ docker-php-ext-install gd; \ @@ -63,30 +84,12 @@ RUN pecl install memcached; \ docker-php-ext-install sysvsem; \ docker-php-ext-install sysvshm; \ docker-php-ext-install bcmath; \ - docker-php-ext-enable mcrypt redis timezonedb apcu; \ + docker-php-ext-enable imagick mcrypt redis timezonedb apcu; \ echo "extension=memcached.so" >> /usr/local/etc/php/conf.d/memcached.ini; \ echo "extension=gmagick.so" >> /usr/local/etc/php/conf.d/gmagick.ini; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ rm -rf /var/lib/apt/lists/*; -# Temp workaround for imagick -RUN apt update && apt install -y git --no-install-recommends && \ - git clone https://github.com/Imagick/imagick.git --depth 1 /tmp/imagick && \ - cd /tmp/imagick && \ - git fetch origin master && \ - git switch master && \ - cd /tmp/imagick && \ - phpize && \ - ./configure && \ - make && \ - make install && \ - docker-php-ext-enable imagick && \ - apt remove -y git && \ - apt autoremove -y && \ - apt clean && \ - rm -rf /var/lib/apt/lists/* && \ - rm -rf /tmp/imagick - # set recommended PHP.ini settings # see https://secure.php.net/manual/en/opcache.installation.php RUN { \ @@ -141,6 +144,25 @@ COPY docker-entrypoint.sh /usr/local/bin/ COPY newrelic.ini /usr/local/etc/php/conf.d/newrelic.ini COPY newrelic.ini /data/newrelic.ini +# Fail the build on a PHP startup warning or error, a broken php-fpm config, wp or composer, or a missing module. +# The list is the previous image's full `php -m`, so it also catches a module dropped from PHP itself. +RUN set -eu; \ + out="$(php -v 2>&1 && php -m 2>&1)"; \ + if printf '%s\n' "$out" | grep -qiE 'warning|error|notice|unable to'; then \ + echo "Build check failed: PHP printed these startup warnings or errors:" >&2; \ + printf '%s\n' "$out" | grep -iE 'warning|error|notice|unable to' >&2; \ + exit 1; \ + fi; \ + php-fpm -t; \ + wp --allow-root --version; \ + COMPOSER_ALLOW_SUPERUSER=1 composer --version; \ + modules="$(php -m | tr '[:upper:] ' '[:lower:]_')"; \ + for m in apcu bcmath calendar core ctype curl date dom exif fileinfo filter gd gmagick gmp hash iconv imagick imap intl json libxml mbstring mcrypt memcached mysqli mysqlnd newrelic openssl pcntl pcre pdo pdo_mysql pdo_sqlite phar posix random readline redis reflection session shmop simplexml soap sockets sodium spl sqlite3 standard sysvsem sysvshm timezonedb tokenizer xml xmlreader xmlwriter zend_opcache zip zlib; do \ + printf '%s\n' "$modules" | grep -qx "$m" || { echo "Build check failed: PHP module $m is missing" >&2; exit 1; }; \ + done; \ + # The checks above leave root-owned logs that www-data couldn't write at runtime; don't ship them + rm -f /var/log/php/access.log /var/log/php/error.log /var/log/newrelic/php_agent.log + WORKDIR /var/www/htdocs RUN usermod -s /bin/bash www-data USER www-data diff --git a/php/8.4/Dockerfile b/php/8.4/Dockerfile index 6ba94e8..551074c 100644 --- a/php/8.4/Dockerfile +++ b/php/8.4/Dockerfile @@ -35,15 +35,41 @@ RUN curl -fsSL https://packages.sury.org/php/README.txt | bash && \ apt-get update && \ apt-get install -y libc-client-dev -RUN pecl install imagick; \ - pecl install memcached; \ - pecl install redis; \ - pecl install apcu; \ - # https://github.com/php/pecl-encryption-mcrypt/issues/7#issuecomment-1050994596 - pecl install -n mcrypt; \ - echo "yes" | pecl install imap; \ - pecl install gmagick-2.0.6RC1; \ - pecl install timezonedb; \ +# Extensions are built with PIE from Packagist/GitHub (not pecl.php.net); docker-php-ext-enable below enables them. +# CI passes its GITHUB_TOKEN as the optional `github_token` BuildKit secret for PIE's GitHub downloads; it never lands in a layer. +RUN --mount=type=secret,id=github_token \ + set -eu; \ + if [ -s /run/secrets/github_token ]; then \ + COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"$(cat /run/secrets/github_token)\"}}"; \ + export COMPOSER_AUTH; \ + fi; \ + set -x; \ + curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ + echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ + chmod +x /usr/local/bin/pie; \ + pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ + pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ + pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \ + pie install --no-interaction --skip-enable-extension apcu/apcu:5.1.28; \ + pie install --no-interaction --skip-enable-extension pecl/mcrypt:1.0.9; \ + # timezonedb stays unpinned: it only exists to ship newer tz data than PHP bundles, so it takes the latest release + pie install --no-interaction --skip-enable-extension pecl/timezonedb; \ + # Record the exact commits PIE installed in the build log + php -r 'foreach (glob("/root/.pie/*/pie.lock") as $f) foreach (json_decode(file_get_contents($f), true)["packages"] as $p) echo "PIE installed ", $p["name"], " ", $p["version"], " ", $p["dist"]["reference"] ?? $p["source"]["reference"] ?? "?", "\n";'; \ + rm -rf /usr/local/bin/pie /root/.pie /root/.composer; \ + # imap and gmagick aren't on Packagist: build the sources of their pecl releases (imap 1.0.3, gmagick 2.0.6RC1) + mkdir /tmp/imap; \ + curl -fsSL -o /tmp/imap.tar.gz https://github.com/php/pecl-mail-imap/archive/refs/tags/1.0.3.tar.gz; \ + echo "529383529b799f7cdefc7fadde028f9ac420bab7b4cb40bbc915ff11fceac18c /tmp/imap.tar.gz" | sha256sum -c -; \ + tar -xzf /tmp/imap.tar.gz -C /tmp/imap --strip-components=1; \ + ( cd /tmp/imap && phpize && ./configure --with-imap --with-kerberos --with-imap-ssl && make -j"$(nproc)" && make install ); \ + rm -rf /tmp/imap /tmp/imap.tar.gz; \ + mkdir /tmp/gmagick; \ + curl -fsSL -o /tmp/gmagick.tar.gz https://github.com/vitoc/gmagick/archive/55423eec7715e89ad63334b35debf582b9566756.tar.gz; \ + echo "01fd8f0b0c7e92cd73b9165fa3ea4b247beb35bad8f6dda85d65e960607e97b5 /tmp/gmagick.tar.gz" | sha256sum -c -; \ + tar -xzf /tmp/gmagick.tar.gz -C /tmp/gmagick --strip-components=1; \ + ( cd /tmp/gmagick && phpize && ./configure && make -j"$(nproc)" && make install ); \ + rm -rf /tmp/gmagick /tmp/gmagick.tar.gz; \ docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \ docker-php-ext-configure zip; \ docker-php-ext-install gd; \ @@ -73,24 +99,6 @@ RUN pecl install imagick; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ rm -rf /var/lib/apt/lists/*; -# Temp workaround for imagick -# RUN apt update && apt install -y git --no-install-recommends && \ -# git clone https://github.com/Imagick/imagick.git --depth 1 /tmp/imagick && \ -# cd /tmp/imagick && \ -# git fetch origin master && \ -# git switch master && \ -# cd /tmp/imagick && \ -# phpize && \ -# ./configure && \ -# make && \ -# make install && \ -# docker-php-ext-enable imagick && \ -# apt remove -y git && \ -# apt autoremove -y && \ -# apt clean && \ -# rm -rf /var/lib/apt/lists/* && \ -# rm -rf /tmp/imagick - # set recommended PHP.ini settings # see https://secure.php.net/manual/en/opcache.installation.php RUN { \ @@ -145,6 +153,25 @@ COPY docker-entrypoint.sh /usr/local/bin/ COPY newrelic.ini /usr/local/etc/php/conf.d/newrelic.ini COPY newrelic.ini /data/newrelic.ini +# Fail the build on a PHP startup warning or error, a broken php-fpm config, wp or composer, or a missing module. +# The list is the previous image's full `php -m`, so it also catches a module dropped from PHP itself. +RUN set -eu; \ + out="$(php -v 2>&1 && php -m 2>&1)"; \ + if printf '%s\n' "$out" | grep -qiE 'warning|error|notice|unable to'; then \ + echo "Build check failed: PHP printed these startup warnings or errors:" >&2; \ + printf '%s\n' "$out" | grep -iE 'warning|error|notice|unable to' >&2; \ + exit 1; \ + fi; \ + php-fpm -t; \ + wp --allow-root --version; \ + COMPOSER_ALLOW_SUPERUSER=1 composer --version; \ + modules="$(php -m | tr '[:upper:] ' '[:lower:]_')"; \ + for m in apcu bcmath calendar core ctype curl date dom exif fileinfo filter gd gmagick gmp hash iconv imagick imap intl json libxml mbstring mcrypt memcached mysqli mysqlnd newrelic openssl pcntl pcre pdo pdo_mysql pdo_sqlite phar posix random readline redis reflection session shmop simplexml soap sockets sodium spl sqlite3 standard sysvsem sysvshm timezonedb tokenizer xml xmlreader xmlwriter zend_opcache zip zlib; do \ + printf '%s\n' "$modules" | grep -qx "$m" || { echo "Build check failed: PHP module $m is missing" >&2; exit 1; }; \ + done; \ + # The checks above leave root-owned logs that www-data couldn't write at runtime; don't ship them + rm -f /var/log/php/access.log /var/log/php/error.log /var/log/newrelic/php_agent.log + WORKDIR /var/www/htdocs RUN usermod -s /bin/bash www-data USER www-data diff --git a/php/8.5/Dockerfile b/php/8.5/Dockerfile index bb52dbd..da0e5cb 100644 --- a/php/8.5/Dockerfile +++ b/php/8.5/Dockerfile @@ -35,14 +35,35 @@ RUN curl -fsSL https://packages.sury.org/php/README.txt | bash && \ apt-get update && \ apt-get install -y libc-client-dev -RUN pecl install memcached; \ - pecl install redis; \ - pecl install apcu; \ - # https://github.com/php/pecl-encryption-mcrypt/issues/7#issuecomment-1050994596 - pecl install -n mcrypt; \ - echo "yes" | pecl install imap; \ - pecl install timezonedb; \ - # pecl install imagick; \ +# Extensions are built with PIE from Packagist/GitHub (not pecl.php.net); docker-php-ext-enable below enables them. +# CI passes its GITHUB_TOKEN as the optional `github_token` BuildKit secret for PIE's GitHub downloads; it never lands in a layer. +RUN --mount=type=secret,id=github_token \ + set -eu; \ + if [ -s /run/secrets/github_token ]; then \ + COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"$(cat /run/secrets/github_token)\"}}"; \ + export COMPOSER_AUTH; \ + fi; \ + set -x; \ + curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ + echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ + chmod +x /usr/local/bin/pie; \ + pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ + pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ + pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \ + pie install --no-interaction --skip-enable-extension apcu/apcu:5.1.28; \ + pie install --no-interaction --skip-enable-extension pecl/mcrypt:1.0.9; \ + # timezonedb stays unpinned: it only exists to ship newer tz data than PHP bundles, so it takes the latest release + pie install --no-interaction --skip-enable-extension pecl/timezonedb; \ + # Record the exact commits PIE installed in the build log + php -r 'foreach (glob("/root/.pie/*/pie.lock") as $f) foreach (json_decode(file_get_contents($f), true)["packages"] as $p) echo "PIE installed ", $p["name"], " ", $p["version"], " ", $p["dist"]["reference"] ?? $p["source"]["reference"] ?? "?", "\n";'; \ + rm -rf /usr/local/bin/pie /root/.pie /root/.composer; \ + # imap isn't on Packagist: build the source of its pecl 1.0.3 release + mkdir /tmp/imap; \ + curl -fsSL -o /tmp/imap.tar.gz https://github.com/php/pecl-mail-imap/archive/refs/tags/1.0.3.tar.gz; \ + echo "529383529b799f7cdefc7fadde028f9ac420bab7b4cb40bbc915ff11fceac18c /tmp/imap.tar.gz" | sha256sum -c -; \ + tar -xzf /tmp/imap.tar.gz -C /tmp/imap --strip-components=1; \ + ( cd /tmp/imap && phpize && ./configure --with-imap --with-kerberos --with-imap-ssl && make -j"$(nproc)" && make install ); \ + rm -rf /tmp/imap /tmp/imap.tar.gz; \ docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \ docker-php-ext-configure zip; \ docker-php-ext-install gd; \ @@ -65,30 +86,12 @@ RUN pecl install memcached; \ docker-php-ext-enable redis; \ docker-php-ext-enable timezonedb; \ docker-php-ext-enable apcu; \ - # docker-php-ext-enable imagick; \ + docker-php-ext-enable imagick; \ echo "extension=memcached.so" >> /usr/local/etc/php/conf.d/memcached.ini; \ echo "extension=imap.so" > /usr/local/etc/php/conf.d/imap.ini; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ rm -rf /var/lib/apt/lists/*; -# Temp workaround for imagick -RUN apt update && apt install -y git --no-install-recommends && \ - git clone https://github.com/Imagick/imagick.git --depth 1 /tmp/imagick && \ - cd /tmp/imagick && \ - git fetch origin master && \ - git switch master && \ - cd /tmp/imagick && \ - phpize && \ - ./configure && \ - make && \ - make install && \ - docker-php-ext-enable imagick && \ - apt remove -y git && \ - apt autoremove -y && \ - apt clean && \ - rm -rf /var/lib/apt/lists/* && \ - rm -rf /tmp/imagick - # set recommended PHP.ini settings # see https://secure.php.net/manual/en/opcache.installation.php RUN { \ @@ -143,6 +146,25 @@ COPY docker-entrypoint.sh /usr/local/bin/ #COPY newrelic.ini /usr/local/etc/php/conf.d/newrelic.ini #COPY newrelic.ini /data/newrelic.ini +# Fail the build on a PHP startup warning or error, a broken php-fpm config, wp or composer, or a missing module. +# The list is the previous image's full `php -m`, so it also catches a module dropped from PHP itself. +RUN set -eu; \ + out="$(php -v 2>&1 && php -m 2>&1)"; \ + if printf '%s\n' "$out" | grep -qiE 'warning|error|notice|unable to'; then \ + echo "Build check failed: PHP printed these startup warnings or errors:" >&2; \ + printf '%s\n' "$out" | grep -iE 'warning|error|notice|unable to' >&2; \ + exit 1; \ + fi; \ + php-fpm -t; \ + wp --allow-root --version; \ + COMPOSER_ALLOW_SUPERUSER=1 composer --version; \ + modules="$(php -m | tr '[:upper:] ' '[:lower:]_')"; \ + for m in apcu bcmath calendar core ctype curl date dom exif fileinfo filter gd gmp hash iconv imagick imap intl json lexbor libxml mbstring mcrypt memcached mysqli mysqlnd openssl pcntl pcre pdo pdo_mysql pdo_sqlite phar posix random readline redis reflection session shmop simplexml soap sockets sodium spl sqlite3 standard sysvsem sysvshm timezonedb tokenizer uri xml xmlreader xmlwriter zend_opcache zip zlib; do \ + printf '%s\n' "$modules" | grep -qx "$m" || { echo "Build check failed: PHP module $m is missing" >&2; exit 1; }; \ + done; \ + # The checks above leave root-owned logs that www-data couldn't write at runtime; don't ship them + rm -f /var/log/php/access.log /var/log/php/error.log + WORKDIR /var/www/htdocs RUN usermod -s /bin/bash www-data USER www-data From 825d97db354553392fd2e445465024f9ec8a9842 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 22 Oct 2026 11:07:14 +0530 Subject: [PATCH 4/5] ci: pass the GitHub token to the PHP image builds The PHP Dockerfiles read an optional github_token BuildKit secret and hand it to PIE, so its GitHub downloads are authenticated instead of anonymous. --- .github/workflows/test_and_publish.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test_and_publish.yml b/.github/workflows/test_and_publish.yml index a802918..2abd6e9 100644 --- a/.github/workflows/test_and_publish.yml +++ b/.github/workflows/test_and_publish.yml @@ -54,6 +54,8 @@ jobs: with: context: php/${{ matrix.php }} tags: easyengine/php${{ steps.img-tag.outputs.tag }}:test + secrets: | + github_token=${{ secrets.GITHUB_TOKEN }} - name: Build and push PHP - ${{ matrix.php }} image uses: docker/build-push-action@v7 @@ -62,6 +64,8 @@ jobs: context: php/${{ matrix.php }} push: true tags: easyengine/php${{ steps.img-tag.outputs.tag }}:${{ steps.tag.outputs.tag }} + secrets: | + github_token=${{ secrets.GITHUB_TOKEN }} other-images: #---------------------------------------------------------------------- From 052c3d2f8b3efaf145a1265d7c69ef9b3c5d5420 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 19 Nov 2026 11:11:16 +0530 Subject: [PATCH 5/5] fix(php): pin PIE's working directory and Composer home in the image builds PIE switches to XDG mode when any XDG_* variable is set or /etc/xdg exists, which moves its working directory to /root/.config/pie and Composer's dirs to /root/.cache/composer, /root/.config/composer and /root/.local/share/composer. The provenance scan (/root/.pie/*/pie.lock) would then print nothing and the cleanup would leave those dirs in the image, so set PIE_WORKING_DIRECTORY and COMPOSER_HOME explicitly. --- php/8.1/Dockerfile | 2 ++ php/8.2/Dockerfile | 2 ++ php/8.3/Dockerfile | 2 ++ php/8.4/Dockerfile | 2 ++ php/8.5/Dockerfile | 2 ++ 5 files changed, 10 insertions(+) diff --git a/php/8.1/Dockerfile b/php/8.1/Dockerfile index ed77107..a1e8b4d 100644 --- a/php/8.1/Dockerfile +++ b/php/8.1/Dockerfile @@ -49,6 +49,8 @@ RUN --mount=type=secret,id=github_token \ curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ chmod +x /usr/local/bin/pie; \ + # Pin PIE's and Composer's dirs so the provenance scan and cleanup below always match. + export PIE_WORKING_DIRECTORY=/root/.pie COMPOSER_HOME=/root/.composer; \ pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \ diff --git a/php/8.2/Dockerfile b/php/8.2/Dockerfile index 6591398..a7c8589 100644 --- a/php/8.2/Dockerfile +++ b/php/8.2/Dockerfile @@ -47,6 +47,8 @@ RUN --mount=type=secret,id=github_token \ curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ chmod +x /usr/local/bin/pie; \ + # Pin PIE's and Composer's dirs so the provenance scan and cleanup below always match. + export PIE_WORKING_DIRECTORY=/root/.pie COMPOSER_HOME=/root/.composer; \ pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \ diff --git a/php/8.3/Dockerfile b/php/8.3/Dockerfile index 8ee9ab9..8c9c18e 100644 --- a/php/8.3/Dockerfile +++ b/php/8.3/Dockerfile @@ -47,6 +47,8 @@ RUN --mount=type=secret,id=github_token \ curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ chmod +x /usr/local/bin/pie; \ + # Pin PIE's and Composer's dirs so the provenance scan and cleanup below always match. + export PIE_WORKING_DIRECTORY=/root/.pie COMPOSER_HOME=/root/.composer; \ pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \ diff --git a/php/8.4/Dockerfile b/php/8.4/Dockerfile index c1c9ee6..63412f7 100644 --- a/php/8.4/Dockerfile +++ b/php/8.4/Dockerfile @@ -47,6 +47,8 @@ RUN --mount=type=secret,id=github_token \ curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ chmod +x /usr/local/bin/pie; \ + # Pin PIE's and Composer's dirs so the provenance scan and cleanup below always match. + export PIE_WORKING_DIRECTORY=/root/.pie COMPOSER_HOME=/root/.composer; \ pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \ diff --git a/php/8.5/Dockerfile b/php/8.5/Dockerfile index d7c0d4f..b4a5c20 100644 --- a/php/8.5/Dockerfile +++ b/php/8.5/Dockerfile @@ -47,6 +47,8 @@ RUN --mount=type=secret,id=github_token \ curl -fsSL -o /usr/local/bin/pie https://github.com/php/pie/releases/download/1.5.2/pie.phar; \ echo "fe70c59738cf56ec00a818cf9cb9593da171aac86f5f1f859995b8839dfd2cc7 /usr/local/bin/pie" | sha256sum -c -; \ chmod +x /usr/local/bin/pie; \ + # Pin PIE's and Composer's dirs so the provenance scan and cleanup below always match. + export PIE_WORKING_DIRECTORY=/root/.pie COMPOSER_HOME=/root/.composer; \ pie install --no-interaction --skip-enable-extension imagick/imagick:3.8.1; \ pie install --no-interaction --skip-enable-extension php-memcached/php-memcached:3.4.0; \ pie install --no-interaction --skip-enable-extension phpredis/phpredis:6.3.0; \