Skip to content

[BUGFIX] Let php.error_log set the error log of PHP-FPM - #632

Merged
Kanti merged 6 commits into
webdevops:masterfrom
andersundsehr:bugfix/php-error-log-setting
Nov 17, 2026
Merged

Kanti merged 6 commits into
webdevops:masterfrom
andersundsehr:bugfix/php-error-log-setting

Conversation

@Kanti

@Kanti Kanti commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The pool sets php_admin_value[error_log] = /docker.stderr, which a php.ini value cannot override, so php.error_log has no effect in PHP-FPM, although the documentation says php.<key> sets any php.ini directive.

The pool keeps /docker.stderr as the default. When php.error_log is set, the entrypoint replaces that line with its value, so php.error_log applies to PHP-FPM as to the CLI.

Related: #476 (PHP error log to a file, /app/error.log), closed, but php.error_log still does not reach PHP-FPM in the published images.

Changes

  • provisioning/php/general/provision/entrypoint.d/20-php-fpm.sh: with php.error_log set, go-replace puts its value into the line php_admin_value[error_log] of the pool; make generate. Replacing the line is needed: PHP-FPM takes the first of two php_admin_value lines for the same directive (php-fpm -tt lists both, the first one applies), so a line added at the end would not take effect.
  • Image test testPhpErrorLogFromTheEnvironment in PhpEnvironmentChecks: with php.error_log=/app/image-test-php-error.log, error_log() in PHP-FPM and in the CLI writes to that file.
  • Image test testPhpErrorsReachTheContainerLogAndTheStderrOfTheCliByDefault: without php.error_log, error_log of PHP-FPM is /docker.stderr, the message of error_log() in PHP-FPM reaches the container log, and the message of error_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.stderr from the stderr of the worker, which PHP-FPM also forwards to the container log.
  • ci/image-tests/Fixtures/app/php-test.php: the case error_log again, 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 case error_log_setting returns ini_get('error_log').
  • docs/known-issues.md, "LOG_STDOUT and LOG_STDERR for PHP-FPM": the errors of PHP scripts do reach the file of LOG_STDERR in php and php-dev, where a worker of PHP-FPM creates it 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 said they never reach it. It now names php.error_log as 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 php and php-dev with LOG_STDERR, the errors of PHP scripts went to the container log instead of that file. The pool value stays, so nothing changes without php.error_log.

Why the test file is in /app

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. A worker of PHP-FPM creates the file as application, so the CLI, run as root by docker exec, could not append to a file in /tmp and wrote its message to stderr (first CI run of this pull request). /app belongs to application and is not sticky.

How it was verified

The published images with the new 20-php-fpm.sh mounted over /opt/docker/provision/entrypoint.d/20-php-fpm.sh, the test page of this pull request, and fs.protected_regular=2 on the host, as on the runners. Where the message of error_log() in PHP-FPM ends up:

Images (8.5, Debian and Alpine) none LOG_STDERR=/app/… LOG_STDERR and fpm.global.error_log=/docker.stderr php.error_log=/app/…
php, php-dev container log file of LOG_STDERR (created by application) file of LOG_STDERR file of php.error_log, also the message of the CLI
php-nginx, php-apache container log container log (the file belongs to root) file of LOG_STDERR file of php.error_log, also the message of the CLI
php-nginx-dev (Alpine), php-apache-dev (Debian) container log container log (the file belongs to root) file of LOG_STDERR file of php.error_log, also the message of the CLI

ini_get('error_log') in PHP-FPM is /docker.stderr in every case without php.error_log, and the file of php.error_log with it. The published images give the same results in the first three columns; with php.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 of error_log() is on the stderr of docker exec, and the container log does not have it.

With php.error_log in /tmp and fs.protected_regular=2, the message of the CLI goes to stderr, as in the first CI run.

Rebased on master with #631; ci/console generate changes nothing else. The CI run of this pull request runs both tests in every PHP image, Debian and Alpine, amd64 and arm64.

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.
@sonarqubecloud

Copy link
Copy Markdown

@Kanti
Kanti marked this pull request as ready for review November 17, 2026 16:49
@Kanti
Kanti merged commit 7ec8faf into webdevops:master Nov 17, 2026
180 checks passed
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.
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