From 0c5007af6295fe0bd15aa09eea761fddffbf9498 Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Thu, 12 Nov 2026 22:42:00 +0000 Subject: [PATCH 1/6] [BUGFIX] Let php.error_log set the error log of PHP-FPM 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. --- ci/image-tests/Checks/PhpEnvironmentChecks.php | 13 +++++++++++++ ci/image-tests/Fixtures/app/php-test.php | 6 ++++++ .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 - .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 - .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 - .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 - .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 - .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 - .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 - .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 - .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 - 11 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ci/image-tests/Checks/PhpEnvironmentChecks.php b/ci/image-tests/Checks/PhpEnvironmentChecks.php index a310374f9..793eecc11 100644 --- a/ci/image-tests/Checks/PhpEnvironmentChecks.php +++ b/ci/image-tests/Checks/PhpEnvironmentChecks.php @@ -177,6 +177,19 @@ public function testPhpSendmailPathFromTheEnvironment(): void } } + /** + * php.error_log, in a container of its own: PHP-FPM and the PHP CLI write the messages of error_log() to that file. + */ + public function testPhpErrorLogFromTheEnvironment(): void + { + $container = $this->startContainer('php-error-log', ['php.error_log' => '/tmp/image-test-php-error.log']); + self::assertSame('logged', $this->phpFpmBody($container, 'test=error_log')); + $this->assertCommandSucceeds("php -r 'error_log(\"image-test-from-the-cli\");'", $container); + $log = $this->stdout('cat /tmp/image-test-php-error.log', $container); + self::assertStringContainsString('image-test-from-php-fpm', $log); + self::assertStringContainsString('image-test-from-the-cli', $log); + } + public function testPhpDismodDisablesExtensionsOfTheCliAndPhpFpm(): void { $container = $this->environmentContainer(); diff --git a/ci/image-tests/Fixtures/app/php-test.php b/ci/image-tests/Fixtures/app/php-test.php index b343ccfa4..293ee312c 100644 --- a/ci/image-tests/Fixtures/app/php-test.php +++ b/ci/image-tests/Fixtures/app/php-test.php @@ -74,6 +74,12 @@ echo 'finished'; break; + case 'error_log': + // a fixed message: one from the request would let the request write into the log + error_log('image-test-from-php-fpm'); + echo 'logged'; + break; + case 'warning': echo $undefinedImageTestVariable; echo 'done'; diff --git a/docker/php-official/8.2-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.2-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index c5d50e3ea..bfca50877 100644 --- a/docker/php-official/8.2-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.2-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,7 +20,6 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ - -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.2/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.2/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index c5d50e3ea..bfca50877 100644 --- a/docker/php-official/8.2/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.2/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,7 +20,6 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ - -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.3-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.3-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index c5d50e3ea..bfca50877 100644 --- a/docker/php-official/8.3-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.3-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,7 +20,6 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ - -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.3/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.3/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index c5d50e3ea..bfca50877 100644 --- a/docker/php-official/8.3/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.3/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,7 +20,6 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ - -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.4-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.4-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index c5d50e3ea..bfca50877 100644 --- a/docker/php-official/8.4-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.4-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,7 +20,6 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ - -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.4/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.4/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index c5d50e3ea..bfca50877 100644 --- a/docker/php-official/8.4/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.4/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,7 +20,6 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ - -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.5-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.5-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index c5d50e3ea..bfca50877 100644 --- a/docker/php-official/8.5-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.5-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,7 +20,6 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ - -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.5/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.5/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index c5d50e3ea..bfca50877 100644 --- a/docker/php-official/8.5/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.5/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,7 +20,6 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ - -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/provisioning/php/general/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/provisioning/php/general/provision/bootstrap.d/20-setup-php-fpm-pool.sh index c5d50e3ea..bfca50877 100644 --- a/provisioning/php/general/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/provisioning/php/general/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,7 +20,6 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ - -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf From b5515083d456b6d0d5670d8eca4f3091718044ed Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Tue, 17 Nov 2026 14:52:04 +0000 Subject: [PATCH 2/6] [TASK] Write the error log of the image test to /app instead of /tmp 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. --- ci/image-tests/Checks/PhpEnvironmentChecks.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ci/image-tests/Checks/PhpEnvironmentChecks.php b/ci/image-tests/Checks/PhpEnvironmentChecks.php index 793eecc11..0e62647a2 100644 --- a/ci/image-tests/Checks/PhpEnvironmentChecks.php +++ b/ci/image-tests/Checks/PhpEnvironmentChecks.php @@ -179,13 +179,15 @@ public function testPhpSendmailPathFromTheEnvironment(): void /** * php.error_log, in a container of its own: PHP-FPM and the PHP CLI write the messages of error_log() to that file. + * The file is in /app, not in /tmp: a worker of PHP-FPM creates it as application, and with fs.protected_regular, + * as on the runners of GitHub Actions, even root may not open the file of another user in a sticky directory. */ public function testPhpErrorLogFromTheEnvironment(): void { - $container = $this->startContainer('php-error-log', ['php.error_log' => '/tmp/image-test-php-error.log']); + $container = $this->startContainer('php-error-log', ['php.error_log' => '/app/image-test-php-error.log']); self::assertSame('logged', $this->phpFpmBody($container, 'test=error_log')); $this->assertCommandSucceeds("php -r 'error_log(\"image-test-from-the-cli\");'", $container); - $log = $this->stdout('cat /tmp/image-test-php-error.log', $container); + $log = $this->stdout('cat /app/image-test-php-error.log', $container); self::assertStringContainsString('image-test-from-php-fpm', $log); self::assertStringContainsString('image-test-from-the-cli', $log); } From 42ebb1bd1b0d7419866c435cae58ed71912d9f9f Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Tue, 17 Nov 2026 16:14:13 +0000 Subject: [PATCH 3/6] [BUGFIX] Keep /docker.stderr as the error log of PHP-FPM unless php.error_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. --- ci/image-tests/Checks/PhpEnvironmentChecks.php | 9 +++++++++ ci/image-tests/Fixtures/app/php-test.php | 4 ++++ .../conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 + .../8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh | 6 ++++++ .../conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 + .../8.2/conf/provision/entrypoint.d/20-php-fpm.sh | 6 ++++++ .../conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 + .../8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh | 6 ++++++ .../conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 + .../8.3/conf/provision/entrypoint.d/20-php-fpm.sh | 6 ++++++ .../conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 + .../8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh | 6 ++++++ .../conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 + .../8.4/conf/provision/entrypoint.d/20-php-fpm.sh | 6 ++++++ .../conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 + .../8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh | 6 ++++++ .../conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 + .../8.5/conf/provision/entrypoint.d/20-php-fpm.sh | 6 ++++++ .../provision/bootstrap.d/20-setup-php-fpm-pool.sh | 1 + .../php/general/provision/entrypoint.d/20-php-fpm.sh | 9 +++++++++ 20 files changed, 79 insertions(+) diff --git a/ci/image-tests/Checks/PhpEnvironmentChecks.php b/ci/image-tests/Checks/PhpEnvironmentChecks.php index 0e62647a2..0d5a59ef7 100644 --- a/ci/image-tests/Checks/PhpEnvironmentChecks.php +++ b/ci/image-tests/Checks/PhpEnvironmentChecks.php @@ -192,6 +192,15 @@ public function testPhpErrorLogFromTheEnvironment(): void self::assertStringContainsString('image-test-from-the-cli', $log); } + /** + * Without php.error_log, PHP-FPM logs the errors of PHP scripts to /docker.stderr, the container log or the file of + * LOG_STDERR. Where a worker of PHP-FPM may write to that file, as in webdevops/php, the errors end up there. + */ + public function testPhpFpmLogsPhpErrorsToDockerStderrByDefault(): void + { + self::assertSame('/docker.stderr', $this->phpFpmBody(self::container(), 'test=error_log_setting')); + } + public function testPhpDismodDisablesExtensionsOfTheCliAndPhpFpm(): void { $container = $this->environmentContainer(); diff --git a/ci/image-tests/Fixtures/app/php-test.php b/ci/image-tests/Fixtures/app/php-test.php index 293ee312c..0f545e304 100644 --- a/ci/image-tests/Fixtures/app/php-test.php +++ b/ci/image-tests/Fixtures/app/php-test.php @@ -80,6 +80,10 @@ echo 'logged'; break; + case 'error_log_setting': + echo ini_get('error_log'); + break; + case 'warning': echo $undefinedImageTestVariable; echo 'done'; diff --git a/docker/php-official/8.2-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.2-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index bfca50877..c5d50e3ea 100644 --- a/docker/php-official/8.2-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.2-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,6 +20,7 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh index 5ab722cf7..71b3a4c16 100644 --- a/docker/php-official/8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh @@ -74,6 +74,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then echo "rlimit_core = ${FPM_RLIMIT_CORE}" >> /opt/docker/etc/php/fpm/pool.d/application.conf fi +# The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, +# so php.error_log replaces it here +if [[ -n "$(envListVars 'php\.error_log=')" ]]; then + echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf +fi + # Workaround for official PHP images if [[ -n "${PHP_SENDMAIL_PATH+x}" ]]; then echo "php_admin_value[sendmail_path] = ${PHP_SENDMAIL_PATH}" >> /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.2/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.2/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index bfca50877..c5d50e3ea 100644 --- a/docker/php-official/8.2/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.2/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,6 +20,7 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.2/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.2/conf/provision/entrypoint.d/20-php-fpm.sh index 5ab722cf7..71b3a4c16 100644 --- a/docker/php-official/8.2/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.2/conf/provision/entrypoint.d/20-php-fpm.sh @@ -74,6 +74,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then echo "rlimit_core = ${FPM_RLIMIT_CORE}" >> /opt/docker/etc/php/fpm/pool.d/application.conf fi +# The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, +# so php.error_log replaces it here +if [[ -n "$(envListVars 'php\.error_log=')" ]]; then + echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf +fi + # Workaround for official PHP images if [[ -n "${PHP_SENDMAIL_PATH+x}" ]]; then echo "php_admin_value[sendmail_path] = ${PHP_SENDMAIL_PATH}" >> /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.3-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.3-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index bfca50877..c5d50e3ea 100644 --- a/docker/php-official/8.3-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.3-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,6 +20,7 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh index 5ab722cf7..71b3a4c16 100644 --- a/docker/php-official/8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh @@ -74,6 +74,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then echo "rlimit_core = ${FPM_RLIMIT_CORE}" >> /opt/docker/etc/php/fpm/pool.d/application.conf fi +# The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, +# so php.error_log replaces it here +if [[ -n "$(envListVars 'php\.error_log=')" ]]; then + echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf +fi + # Workaround for official PHP images if [[ -n "${PHP_SENDMAIL_PATH+x}" ]]; then echo "php_admin_value[sendmail_path] = ${PHP_SENDMAIL_PATH}" >> /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.3/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.3/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index bfca50877..c5d50e3ea 100644 --- a/docker/php-official/8.3/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.3/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,6 +20,7 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.3/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.3/conf/provision/entrypoint.d/20-php-fpm.sh index 5ab722cf7..71b3a4c16 100644 --- a/docker/php-official/8.3/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.3/conf/provision/entrypoint.d/20-php-fpm.sh @@ -74,6 +74,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then echo "rlimit_core = ${FPM_RLIMIT_CORE}" >> /opt/docker/etc/php/fpm/pool.d/application.conf fi +# The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, +# so php.error_log replaces it here +if [[ -n "$(envListVars 'php\.error_log=')" ]]; then + echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf +fi + # Workaround for official PHP images if [[ -n "${PHP_SENDMAIL_PATH+x}" ]]; then echo "php_admin_value[sendmail_path] = ${PHP_SENDMAIL_PATH}" >> /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.4-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.4-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index bfca50877..c5d50e3ea 100644 --- a/docker/php-official/8.4-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.4-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,6 +20,7 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh index 5ab722cf7..71b3a4c16 100644 --- a/docker/php-official/8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh @@ -74,6 +74,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then echo "rlimit_core = ${FPM_RLIMIT_CORE}" >> /opt/docker/etc/php/fpm/pool.d/application.conf fi +# The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, +# so php.error_log replaces it here +if [[ -n "$(envListVars 'php\.error_log=')" ]]; then + echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf +fi + # Workaround for official PHP images if [[ -n "${PHP_SENDMAIL_PATH+x}" ]]; then echo "php_admin_value[sendmail_path] = ${PHP_SENDMAIL_PATH}" >> /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.4/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.4/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index bfca50877..c5d50e3ea 100644 --- a/docker/php-official/8.4/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.4/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,6 +20,7 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.4/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.4/conf/provision/entrypoint.d/20-php-fpm.sh index 5ab722cf7..71b3a4c16 100644 --- a/docker/php-official/8.4/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.4/conf/provision/entrypoint.d/20-php-fpm.sh @@ -74,6 +74,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then echo "rlimit_core = ${FPM_RLIMIT_CORE}" >> /opt/docker/etc/php/fpm/pool.d/application.conf fi +# The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, +# so php.error_log replaces it here +if [[ -n "$(envListVars 'php\.error_log=')" ]]; then + echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf +fi + # Workaround for official PHP images if [[ -n "${PHP_SENDMAIL_PATH+x}" ]]; then echo "php_admin_value[sendmail_path] = ${PHP_SENDMAIL_PATH}" >> /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.5-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.5-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index bfca50877..c5d50e3ea 100644 --- a/docker/php-official/8.5-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.5-alpine/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,6 +20,7 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh index 5ab722cf7..71b3a4c16 100644 --- a/docker/php-official/8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh @@ -74,6 +74,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then echo "rlimit_core = ${FPM_RLIMIT_CORE}" >> /opt/docker/etc/php/fpm/pool.d/application.conf fi +# The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, +# so php.error_log replaces it here +if [[ -n "$(envListVars 'php\.error_log=')" ]]; then + echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf +fi + # Workaround for official PHP images if [[ -n "${PHP_SENDMAIL_PATH+x}" ]]; then echo "php_admin_value[sendmail_path] = ${PHP_SENDMAIL_PATH}" >> /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.5/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/docker/php-official/8.5/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh index bfca50877..c5d50e3ea 100644 --- a/docker/php-official/8.5/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/docker/php-official/8.5/conf/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,6 +20,7 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/docker/php-official/8.5/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.5/conf/provision/entrypoint.d/20-php-fpm.sh index 5ab722cf7..71b3a4c16 100644 --- a/docker/php-official/8.5/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.5/conf/provision/entrypoint.d/20-php-fpm.sh @@ -74,6 +74,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then echo "rlimit_core = ${FPM_RLIMIT_CORE}" >> /opt/docker/etc/php/fpm/pool.d/application.conf fi +# The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, +# so php.error_log replaces it here +if [[ -n "$(envListVars 'php\.error_log=')" ]]; then + echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf +fi + # Workaround for official PHP images if [[ -n "${PHP_SENDMAIL_PATH+x}" ]]; then echo "php_admin_value[sendmail_path] = ${PHP_SENDMAIL_PATH}" >> /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/provisioning/php/general/provision/bootstrap.d/20-setup-php-fpm-pool.sh b/provisioning/php/general/provision/bootstrap.d/20-setup-php-fpm-pool.sh index bfca50877..c5d50e3ea 100644 --- a/provisioning/php/general/provision/bootstrap.d/20-setup-php-fpm-pool.sh +++ b/provisioning/php/general/provision/bootstrap.d/20-setup-php-fpm-pool.sh @@ -20,6 +20,7 @@ go-replace --mode=lineinfile --regex \ -s '^[\s;]*access.format[\s]*=' -r 'access.format = "[php-fpm:access] %R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \ -s '^[\s;]*access.log[\s]*=' -r 'access.log = /docker.stdout' \ -s '^[\s;]*slowlog[\s]*=' -r 'slowlog = /docker.stderr' \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r 'php_admin_value[error_log] = /docker.stderr' \ -s '^[\s;]*php_admin_value\[log_errors\][\s]*=' -r 'php_admin_value[log_errors] = on' \ -s '^[\s;]*listen.allowed_clients[\s]*=' -r ";listen.allowed_clients" \ -- /opt/docker/etc/php/fpm/pool.d/application.conf diff --git a/provisioning/php/general/provision/entrypoint.d/20-php-fpm.sh b/provisioning/php/general/provision/entrypoint.d/20-php-fpm.sh index 5ab722cf7..0bcd0b8d1 100644 --- a/provisioning/php/general/provision/entrypoint.d/20-php-fpm.sh +++ b/provisioning/php/general/provision/entrypoint.d/20-php-fpm.sh @@ -74,6 +74,15 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then echo "rlimit_core = ${FPM_RLIMIT_CORE}" >> /opt/docker/etc/php/fpm/pool.d/application.conf fi +# The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, +# so php.error_log replaces it here. PHP-FPM takes the first of two php_admin_value lines, so a line added below would +# not take effect. +if [[ -n "$(envListVars 'php\.error_log=')" ]]; then + go-replace --mode=lineinfile --regex \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r "php_admin_value[error_log] = $(envGetValue php.error_log)" \ + -- /opt/docker/etc/php/fpm/pool.d/application.conf +fi + # Workaround for official PHP images if [[ -n "${PHP_SENDMAIL_PATH+x}" ]]; then echo "php_admin_value[sendmail_path] = ${PHP_SENDMAIL_PATH}" >> /opt/docker/etc/php/fpm/pool.d/application.conf From 0701538e0f03e66cd1816fe75a53b4199e42df82 Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Tue, 17 Nov 2026 16:21:52 +0000 Subject: [PATCH 4/6] [TASK] Check that PHP errors reach the container log, and say where they 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. --- ci/image-tests/Checks/PhpEnvironmentChecks.php | 13 ++++++++++--- docs/environment-variables.md | 2 +- docs/known-issues.md | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ci/image-tests/Checks/PhpEnvironmentChecks.php b/ci/image-tests/Checks/PhpEnvironmentChecks.php index 0d5a59ef7..4e11b1487 100644 --- a/ci/image-tests/Checks/PhpEnvironmentChecks.php +++ b/ci/image-tests/Checks/PhpEnvironmentChecks.php @@ -193,12 +193,19 @@ public function testPhpErrorLogFromTheEnvironment(): void } /** - * Without php.error_log, PHP-FPM logs the errors of PHP scripts to /docker.stderr, the container log or the file of - * LOG_STDERR. Where a worker of PHP-FPM may write to that file, as in webdevops/php, the errors end up there. + * Without php.error_log, PHP-FPM logs the errors of PHP scripts to /docker.stderr, which the container of the class, + * without LOG_STDERR, links to the stderr of the container: the message of error_log() reaches the container log. + * With LOG_STDERR, it reaches that file where a worker of PHP-FPM may write to it, as in webdevops/php; the setting + * is checked too, because the container log alone would not tell /docker.stderr from the stderr of the worker. */ public function testPhpFpmLogsPhpErrorsToDockerStderrByDefault(): void { - self::assertSame('/docker.stderr', $this->phpFpmBody(self::container(), 'test=error_log_setting')); + $container = self::container(); + self::assertSame('/docker.stderr', $this->phpFpmBody($container, 'test=error_log_setting')); + self::assertSame('logged', $this->phpFpmBody($container, 'test=error_log')); + $this->eventually(function () use ($container): void { + self::assertStringContainsString('PHP message: image-test-from-php-fpm', $container->logs()); + }); } public function testPhpDismodDisablesExtensionsOfTheCliAndPhpFpm(): void diff --git a/docs/environment-variables.md b/docs/environment-variables.md index d8cf559c1..b3f33de05 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -36,7 +36,7 @@ Images: `base`, `base-app`, `apache`, `nginx`, `php-*`. | --- | --- | --- | | `CLI_SCRIPT` | not set | Command the `cli` entrypoint runs as `APPLICATION_USER`. Works in `base-app` and `php-*` only; in the other images `cli` fails because `APPLICATION_USER` is not set. See [Customization](customization.md#commands). | | `LOG_STDOUT` | container stdout | File that `/docker.stdout` points to. Nginx and Apache write their access logs there, syslog-ng the messages of the services, for example of cron and Postfix. PHP-FPM does not, see [Known issues](known-issues.md#log_stdout-and-log_stderr-for-php-fpm). | -| `LOG_STDERR` | container stderr | File that `/docker.stderr` points to. Nginx and Apache write their error logs there. | +| `LOG_STDERR` | container stderr | File that `/docker.stderr` points to. Nginx and Apache write their error logs there. The errors of PHP scripts end up there only in `php` and `php-dev`, see [Known issues](known-issues.md#log_stdout-and-log_stderr-for-php-fpm). | | `TZ` | not set (UTC) | Time zone of the container, for example `Europe/Berlin`. It applies to `date`, cron and the time stamps supervisord writes to the container log. PHP uses `PHP_DATE_TIMEZONE` instead, see [Time zone](customization.md#time-zone). | ## Web server diff --git a/docs/known-issues.md b/docs/known-issues.md index b7997aafa..879fba885 100644 --- a/docs/known-issues.md +++ b/docs/known-issues.md @@ -18,9 +18,9 @@ These options and tools are part of the images but do not work, or work only in ### `LOG_STDOUT` and `LOG_STDERR` for PHP-FPM -- **Effect:** PHP-FPM writes its access log, its own messages and the errors of PHP scripts to the stderr of the container, not to `/docker.stdout` and `/docker.stderr`, so `LOG_STDOUT` and `LOG_STDERR` do not apply to it. The `docker.conf` of the official PHP image sets `error_log` and `access.log` to `/proc/self/fd/2` after the configuration of the image. -- **Images:** `php-*`, Debian and Alpine. -- **Instead:** Read them with `docker compose logs`. To have PHP-FPM's messages and the PHP errors in the file of `LOG_STDERR`, also set `fpm.global.error_log: /docker.stderr`. The access log needs a pool file that sorts after `docker.conf`, see [`fpm.pool.`](#fpmpoolkey-for-the-directives-of-dockerconf). +- **Effect:** PHP-FPM writes its access log and its own messages to the stderr of the container, not to `/docker.stdout` and `/docker.stderr`, so `LOG_STDOUT` and `LOG_STDERR` do not apply to them. The `docker.conf` of the official PHP image sets `error_log` and `access.log` to `/proc/self/fd/2` after the configuration of the image. The errors of PHP scripts go to `/docker.stderr`, but the workers of PHP-FPM run as `application` and can only write to a file that they may open. In `php` and `php-dev`, they create the file of `LOG_STDERR` and write the errors there. In the images with Nginx or Apache, the web server creates that file as root first, so the errors go to the stderr of the container, as they do in every image without `LOG_STDERR`. +- **Images:** `php`, `php-dev`, `php-nginx`, `php-nginx-dev`, `php-apache` and `php-apache-dev`, Debian and Alpine. +- **Instead:** Read them with `docker compose logs`. To have PHP-FPM's messages and the PHP errors in the file of `LOG_STDERR` in every image, also set `fpm.global.error_log: /docker.stderr`. `php.error_log` gives the PHP errors of PHP-FPM and the CLI a file of their own, in a directory that `application` may write to, for example `/app`. The access log needs a pool file that sorts after `docker.conf`, see [`fpm.pool.`](#fpmpoolkey-for-the-directives-of-dockerconf). ### No `/app` in `nginx` and `apache` From e2322c23c28997303579b42068695da3e7ed6646 Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Tue, 17 Nov 2026 16:22:05 +0000 Subject: [PATCH 5/6] [TASK] Regenerate the PHP-FPM entrypoint of the images The generated copies of 20-php-fpm.sh still added a second line instead of replacing php_admin_value[error_log]. --- .../8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh | 7 +++++-- .../8.2/conf/provision/entrypoint.d/20-php-fpm.sh | 7 +++++-- .../8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh | 7 +++++-- .../8.3/conf/provision/entrypoint.d/20-php-fpm.sh | 7 +++++-- .../8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh | 7 +++++-- .../8.4/conf/provision/entrypoint.d/20-php-fpm.sh | 7 +++++-- .../8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh | 7 +++++-- .../8.5/conf/provision/entrypoint.d/20-php-fpm.sh | 7 +++++-- 8 files changed, 40 insertions(+), 16 deletions(-) diff --git a/docker/php-official/8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh index 71b3a4c16..0bcd0b8d1 100644 --- a/docker/php-official/8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.2-alpine/conf/provision/entrypoint.d/20-php-fpm.sh @@ -75,9 +75,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then fi # The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, -# so php.error_log replaces it here +# so php.error_log replaces it here. PHP-FPM takes the first of two php_admin_value lines, so a line added below would +# not take effect. if [[ -n "$(envListVars 'php\.error_log=')" ]]; then - echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf + go-replace --mode=lineinfile --regex \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r "php_admin_value[error_log] = $(envGetValue php.error_log)" \ + -- /opt/docker/etc/php/fpm/pool.d/application.conf fi # Workaround for official PHP images diff --git a/docker/php-official/8.2/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.2/conf/provision/entrypoint.d/20-php-fpm.sh index 71b3a4c16..0bcd0b8d1 100644 --- a/docker/php-official/8.2/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.2/conf/provision/entrypoint.d/20-php-fpm.sh @@ -75,9 +75,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then fi # The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, -# so php.error_log replaces it here +# so php.error_log replaces it here. PHP-FPM takes the first of two php_admin_value lines, so a line added below would +# not take effect. if [[ -n "$(envListVars 'php\.error_log=')" ]]; then - echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf + go-replace --mode=lineinfile --regex \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r "php_admin_value[error_log] = $(envGetValue php.error_log)" \ + -- /opt/docker/etc/php/fpm/pool.d/application.conf fi # Workaround for official PHP images diff --git a/docker/php-official/8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh index 71b3a4c16..0bcd0b8d1 100644 --- a/docker/php-official/8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.3-alpine/conf/provision/entrypoint.d/20-php-fpm.sh @@ -75,9 +75,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then fi # The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, -# so php.error_log replaces it here +# so php.error_log replaces it here. PHP-FPM takes the first of two php_admin_value lines, so a line added below would +# not take effect. if [[ -n "$(envListVars 'php\.error_log=')" ]]; then - echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf + go-replace --mode=lineinfile --regex \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r "php_admin_value[error_log] = $(envGetValue php.error_log)" \ + -- /opt/docker/etc/php/fpm/pool.d/application.conf fi # Workaround for official PHP images diff --git a/docker/php-official/8.3/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.3/conf/provision/entrypoint.d/20-php-fpm.sh index 71b3a4c16..0bcd0b8d1 100644 --- a/docker/php-official/8.3/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.3/conf/provision/entrypoint.d/20-php-fpm.sh @@ -75,9 +75,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then fi # The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, -# so php.error_log replaces it here +# so php.error_log replaces it here. PHP-FPM takes the first of two php_admin_value lines, so a line added below would +# not take effect. if [[ -n "$(envListVars 'php\.error_log=')" ]]; then - echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf + go-replace --mode=lineinfile --regex \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r "php_admin_value[error_log] = $(envGetValue php.error_log)" \ + -- /opt/docker/etc/php/fpm/pool.d/application.conf fi # Workaround for official PHP images diff --git a/docker/php-official/8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh index 71b3a4c16..0bcd0b8d1 100644 --- a/docker/php-official/8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.4-alpine/conf/provision/entrypoint.d/20-php-fpm.sh @@ -75,9 +75,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then fi # The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, -# so php.error_log replaces it here +# so php.error_log replaces it here. PHP-FPM takes the first of two php_admin_value lines, so a line added below would +# not take effect. if [[ -n "$(envListVars 'php\.error_log=')" ]]; then - echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf + go-replace --mode=lineinfile --regex \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r "php_admin_value[error_log] = $(envGetValue php.error_log)" \ + -- /opt/docker/etc/php/fpm/pool.d/application.conf fi # Workaround for official PHP images diff --git a/docker/php-official/8.4/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.4/conf/provision/entrypoint.d/20-php-fpm.sh index 71b3a4c16..0bcd0b8d1 100644 --- a/docker/php-official/8.4/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.4/conf/provision/entrypoint.d/20-php-fpm.sh @@ -75,9 +75,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then fi # The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, -# so php.error_log replaces it here +# so php.error_log replaces it here. PHP-FPM takes the first of two php_admin_value lines, so a line added below would +# not take effect. if [[ -n "$(envListVars 'php\.error_log=')" ]]; then - echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf + go-replace --mode=lineinfile --regex \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r "php_admin_value[error_log] = $(envGetValue php.error_log)" \ + -- /opt/docker/etc/php/fpm/pool.d/application.conf fi # Workaround for official PHP images diff --git a/docker/php-official/8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh index 71b3a4c16..0bcd0b8d1 100644 --- a/docker/php-official/8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.5-alpine/conf/provision/entrypoint.d/20-php-fpm.sh @@ -75,9 +75,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then fi # The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, -# so php.error_log replaces it here +# so php.error_log replaces it here. PHP-FPM takes the first of two php_admin_value lines, so a line added below would +# not take effect. if [[ -n "$(envListVars 'php\.error_log=')" ]]; then - echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf + go-replace --mode=lineinfile --regex \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r "php_admin_value[error_log] = $(envGetValue php.error_log)" \ + -- /opt/docker/etc/php/fpm/pool.d/application.conf fi # Workaround for official PHP images diff --git a/docker/php-official/8.5/conf/provision/entrypoint.d/20-php-fpm.sh b/docker/php-official/8.5/conf/provision/entrypoint.d/20-php-fpm.sh index 71b3a4c16..0bcd0b8d1 100644 --- a/docker/php-official/8.5/conf/provision/entrypoint.d/20-php-fpm.sh +++ b/docker/php-official/8.5/conf/provision/entrypoint.d/20-php-fpm.sh @@ -75,9 +75,12 @@ if [[ -n "${FPM_RLIMIT_CORE+x}" ]]; then fi # The pool logs the errors of PHP scripts to /docker.stderr with php_admin_value, which a php.ini value cannot override, -# so php.error_log replaces it here +# so php.error_log replaces it here. PHP-FPM takes the first of two php_admin_value lines, so a line added below would +# not take effect. if [[ -n "$(envListVars 'php\.error_log=')" ]]; then - echo "php_admin_value[error_log] = $(envGetValue php.error_log)" >> /opt/docker/etc/php/fpm/pool.d/application.conf + go-replace --mode=lineinfile --regex \ + -s '^[\s;]*php_admin_value\[error_log\][\s]*=' -r "php_admin_value[error_log] = $(envGetValue php.error_log)" \ + -- /opt/docker/etc/php/fpm/pool.d/application.conf fi # Workaround for official PHP images From 2de282cf0e600d0e4cc1a173e0c0dbac306b0252 Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Tue, 17 Nov 2026 16:25:57 +0000 Subject: [PATCH 6/6] [TASK] Check where the errors of the PHP CLI go without php.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. --- ci/image-tests/Checks/PhpEnvironmentChecks.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ci/image-tests/Checks/PhpEnvironmentChecks.php b/ci/image-tests/Checks/PhpEnvironmentChecks.php index 4e11b1487..6bd338666 100644 --- a/ci/image-tests/Checks/PhpEnvironmentChecks.php +++ b/ci/image-tests/Checks/PhpEnvironmentChecks.php @@ -197,8 +197,10 @@ public function testPhpErrorLogFromTheEnvironment(): void * without LOG_STDERR, links to the stderr of the container: the message of error_log() reaches the container log. * With LOG_STDERR, it reaches that file where a worker of PHP-FPM may write to it, as in webdevops/php; the setting * is checked too, because the container log alone would not tell /docker.stderr from the stderr of the worker. + * The PHP CLI has no error log of its own: its messages go to the stderr of the command, e.g. of docker compose + * exec, not to the container log. */ - public function testPhpFpmLogsPhpErrorsToDockerStderrByDefault(): void + public function testPhpErrorsReachTheContainerLogAndTheStderrOfTheCliByDefault(): void { $container = self::container(); self::assertSame('/docker.stderr', $this->phpFpmBody($container, 'test=error_log_setting')); @@ -206,6 +208,10 @@ public function testPhpFpmLogsPhpErrorsToDockerStderrByDefault(): void $this->eventually(function () use ($container): void { self::assertStringContainsString('PHP message: image-test-from-php-fpm', $container->logs()); }); + + $cli = $this->assertCommandSucceeds("php -r 'error_log(\"image-test-from-the-cli\");'", $container); + self::assertStringContainsString('image-test-from-the-cli', $cli->stderr); + self::assertStringNotContainsString('image-test-from-the-cli', $container->logs()); } public function testPhpDismodDisablesExtensionsOfTheCliAndPhpFpm(): void