Repository navigation
Add an Apache variant and let PHP-FPM finish requests on stop - #265
Merged
Merged
Conversation
PHP-FPM only waits for running scripts on SIGQUIT, the image's stop signal, when process_control_timeout is set. The image never set it, so stopping a container cut off requests in progress. Give them up to 20 seconds by default, within Kubernetes' default 30-second grace period, and make the limit configurable with PHP_FPM_PROCESS_CONTROL_TIMEOUT.
Ready-to-use PHP applications need a web server that can see their static files. With the web server in another container, the files must be built into a second image. The new apache stage runs Apache in front of PHP-FPM in the same container, so an application image built on it needs no separate web server. Apache serves static files and .htaccess rules and passes PHP scripts to the local PHP-FPM over FastCGI. X-Forwarded-Proto: https sets HTTPS=on, as wodby/nginx does, and the Authorization header reaches PHP. The php-fpm-apache command runs both servers, stops the container when either exits and stops both gracefully. /.healthz answers 204 and check-ready also checks Apache. PHP_WEB=apache make builds and tests the stage as <minor>-apache. Builds without a target still produce the PHP-FPM image. The variant has its own test, apache.sh, because its PHP layer is the one run.sh already tests.
The build matrix adds the apache variant for every PHP version and both architectures, without development images. It is tested with apache.sh and scanned like the other images. Releases tag it <minor>-apache, and the latest PHP version also <major>-apache. Revision tags follow the same pattern (<minor>-apache-rN), and the revision aliases add <version>-apache-rN. The variant gets no latest tag.
This was referenced Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Ready-to-use PHP applications such as Mautic, Matomo or Adminer can't run from a single prebuilt image based on
wodby/php. The image only runs PHP-FPM, so a separate web server container must serve the application's static files. That container can't see files baked into the PHP image, so today every such application has to be built from the customer's own repository, once for the PHP image and once for the web server image.Separately, when a PHP-FPM container is stopped, requests that are still running are cut off instead of finishing.
Cause
wodby/phphas no web server, and a web server in another container only sees files that are copied into its own image or shared through a volume.PHP-FPM only waits for running scripts on a graceful stop when
process_control_timeoutis set, and the image never set it.Solution
Add an
-apachevariant of every PHP version. Apache runs in the same container as PHP-FPM: it serves static files and the application's own.htaccessrules, and hands PHP scripts to the PHP-FPM next to it. An application image can then be built once on top of it and run without a separate web server or a customer build. The existing images and tags don't change.PHP-FPM now gives running scripts up to 20 seconds to finish on a graceful stop, in every image. The new
PHP_FPM_PROCESS_CONTROL_TIMEOUTvariable changes the limit, and0restores the previous behavior.Details
phpstage; a newapachestage adds Alpine'sapache2andapache2-proxyon top of it.PHP_WEB=apache makebuilds theapachestage and tags it<minor>-apache; builds without a target still produce the PHP-FPM image.www-data, listens on port 80 and passes PHP scripts to127.0.0.1:9000over FastCGI. The configuration is rendered fromAPACHE_*variables, following the names ofwodby/apache(documented in the README).X-Forwarded-Proto: httpssetsHTTPS=on, matching whatwodby/nginxpasses to PHP-FPM.CGIPassAuthpasses theAuthorizationheader.X-Forwarded-Foris applied to the client address only whenAPACHE_REMOTEIP_TRUSTED_PROXIESis set.php-fpm-apache, the default command, runs both servers and stops the container when either exits. A stop signal gracefully stops Apache (httpd -k graceful-stop, at mostAPACHE_GRACEFUL_SHUTDOWN_TIMEOUTseconds) and PHP-FPM. Other commands, such as cron jobs or queue workers, run without Apache./.healthzanswers 204, and thecheck-readyaction checks Apache as well as PHP-FPM in this variant.wodbymay runhttpdwithsudo, as it may already runphp-fpm. Like the PHP-FPM configuration, the Apache configuration is rendered by the entrypoint aswodby.-devvariant. Release revisions get<minor>-apache-rNand<version>-apache-rNtags, and8-apachefollows the latest PHP version.Validation
8.4-apacheand8.4locally from scratch withmake(arm64).PHP_WEB=apache make test(8/tests/apache.sh) passes:.htaccessrewrites;HTTPS=onbehind a proxy, theAuthorizationheader;/.healthz;8.5-apache,8-apacheand8.5-apache-r12for the variant and unchanged tags for the other images. The workflow and action parse.make -nshows every build target passes the stage, andPHP_WEB=apache PHP_DEV=1is refused.