Repository navigation
[BUGFIX] Let php.error_log set the error log of PHP-FPM - #632
Merged
Kanti merged 6 commits intoNov 17, 2026
Merged
Conversation
The pool set php_admin_value[error_log] = /docker.stderr, which a php.ini value cannot override, so php.error_log had no effect in PHP-FPM. The workers, which run as application, cannot open /docker.stderr either, so PHP fell back to the stderr of the worker, which PHP-FPM forwards to its own log. Without the pool value, PHP does the same by default, and php.error_log now applies to PHP-FPM as to the CLI. The PHP test page gets its error_log case back for the image test, with a fixed message instead of one from the request.
On the runners of GitHub Actions, fs.protected_regular is set: even root may not open a file of another user in a sticky directory such as /tmp with O_CREAT. A worker of PHP-FPM created the log file as application, so the PHP CLI, run as root, could not append to it and wrote its message to stderr. /app belongs to application and is not sticky.
…rror_log is set Without the pool value, PHP-FPM no longer logged the errors of PHP scripts to /docker.stderr. Where a worker may write to the file of LOG_STDERR, as in webdevops/php, they went to the container log instead of that file. The pool keeps php_admin_value[error_log] = /docker.stderr, and the entrypoint replaces the line with the value of php.error_log when it is set. Adding a second line would not work: PHP-FPM takes the first of two php_admin_value lines for the same directive. A new image test checks that PHP-FPM logs to /docker.stderr by default.
…hey go with LOG_STDERR testPhpFpmLogsPhpErrorsToDockerStderrByDefault also sends error_log() to PHP-FPM and looks for the message in the container log, besides the setting, which tells /docker.stderr from the stderr of the worker. docs/known-issues.md said that the errors of PHP scripts never reach the file of LOG_STDERR. In php and php-dev they do: a worker of PHP-FPM creates the file as application. In the images with Nginx or Apache, the web server creates it as root first, and the errors go to the container log. The entry names php.error_log as the way to a file of their own.
The generated copies of 20-php-fpm.sh still added a second line instead of replacing php_admin_value[error_log].
The PHP CLI has no error log of its own: the message of error_log() goes to the stderr of the command, e.g. of docker compose exec, and not to the container log. The test of the default checks that too, and is named after both.
|
Kanti
marked this pull request as ready for review
November 17, 2026 16:49
Kanti
added a commit
to andersundsehr/Dockerfile
that referenced
this pull request
Nov 17, 2026
…of /tmp The runners of GitHub Actions set fs.protected_regular, under which even root may not open a file of another user in a sticky directory such as /tmp with O_CREAT. An image test that lets PHP-FPM, as application, and a command run as root by docker exec write the same file there passes on a Docker host without the setting and fails in the CI, as the first run of webdevops#632 did.
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.



Summary
The pool sets
php_admin_value[error_log] = /docker.stderr, which a php.ini value cannot override, sophp.error_loghas no effect in PHP-FPM, although the documentation saysphp.<key>sets any php.ini directive.The pool keeps
/docker.stderras the default. Whenphp.error_logis set, the entrypoint replaces that line with its value, sophp.error_logapplies to PHP-FPM as to the CLI.Related: #476 (PHP error log to a file,
/app/error.log), closed, butphp.error_logstill does not reach PHP-FPM in the published images.Changes
provisioning/php/general/provision/entrypoint.d/20-php-fpm.sh: withphp.error_logset,go-replaceputs its value into the linephp_admin_value[error_log]of the pool;make generate. Replacing the line is needed: PHP-FPM takes the first of twophp_admin_valuelines for the same directive (php-fpm -ttlists both, the first one applies), so a line added at the end would not take effect.testPhpErrorLogFromTheEnvironmentinPhpEnvironmentChecks: withphp.error_log=/app/image-test-php-error.log,error_log()in PHP-FPM and in the CLI writes to that file.testPhpErrorsReachTheContainerLogAndTheStderrOfTheCliByDefault: withoutphp.error_log,error_logof PHP-FPM is/docker.stderr, the message oferror_log()in PHP-FPM reaches the container log, and the message oferror_log()in the PHP CLI reaches the stderr of the command and not the container log. The setting is checked too, because the container log alone would not tell/docker.stderrfrom the stderr of the worker, which PHP-FPM also forwards to the container log.ci/image-tests/Fixtures/app/php-test.php: the caseerror_logagain, which [!!!][TASK] Test the images with PHPUnit instead of serverspec, test the documented options and remove Ruby #613 had removed as unused; it logs a fixed message instead of one from the request, which SonarCloud had reported as log injection. A caseerror_log_settingreturnsini_get('error_log').docs/known-issues.md, "LOG_STDOUTandLOG_STDERRfor PHP-FPM": the errors of PHP scripts do reach the file ofLOG_STDERRinphpandphp-dev, where a worker of PHP-FPM creates it asapplication; in the images with Nginx or Apache, the web server creates it as root first, and the errors go to the container log. The entry said they never reach it. It now namesphp.error_logas the way to a file of their own.docs/environment-variables.md,LOG_STDERR: the same in one sentence, with a link to the entry.Why not just remove the pool value
The first version of this pull request removed the pool value. That changed the default: in
phpandphp-devwithLOG_STDERR, the errors of PHP scripts went to the container log instead of that file. The pool value stays, so nothing changes withoutphp.error_log.Why the test file is in
/appThe runners of GitHub Actions set
fs.protected_regular, under which even root may not open a file of another user in a sticky directory such as/tmpwithO_CREAT. A worker of PHP-FPM creates the file asapplication, so the CLI, run as root bydocker exec, could not append to a file in/tmpand wrote its message to stderr (first CI run of this pull request)./appbelongs toapplicationand is not sticky.How it was verified
The published images with the new
20-php-fpm.shmounted over/opt/docker/provision/entrypoint.d/20-php-fpm.sh, the test page of this pull request, andfs.protected_regular=2on the host, as on the runners. Where the message oferror_log()in PHP-FPM ends up:LOG_STDERR=/app/…LOG_STDERRandfpm.global.error_log=/docker.stderrphp.error_log=/app/…php,php-devLOG_STDERR(created byapplication)LOG_STDERRphp.error_log, also the message of the CLIphp-nginx,php-apacheLOG_STDERRphp.error_log, also the message of the CLIphp-nginx-dev(Alpine),php-apache-dev(Debian)LOG_STDERRphp.error_log, also the message of the CLIini_get('error_log')in PHP-FPM is/docker.stderrin every case withoutphp.error_log, and the file ofphp.error_logwith it. The published images give the same results in the first three columns; withphp.error_log, they keep/docker.stderr, and the file has only the message of the CLI.The PHP CLI without
php.error_log(php,php-nginx, Debian and Alpine,php-dev,php-nginx-dev:8.5-alpine,php-apache-dev:8.5):ini_get('error_log')is empty, the message oferror_log()is on the stderr ofdocker exec, and the container log does not have it.With
php.error_login/tmpandfs.protected_regular=2, the message of the CLI goes to stderr, as in the first CI run.Rebased on master with #631;
ci/console generatechanges nothing else. The CI run of this pull request runs both tests in every PHP image, Debian and Alpine, amd64 and arm64.