I've been playing around recently with moving away from file based logging locally in a PHP app, to pushing PHP errors through stdout so they're output alongside the other logs in a docker setup. This works fine, if you set the error_log
location to /dev/stdout
then I see errors from PHP through tailing docker logs. However, these same errors also appear in the nginx container, as below via "FastCGI sent in stderr":
docker-compose-nginx-phpfpm-php-fpm-1 | NOTICE: PHP message: test
docker-compose-nginx-phpfpm-php-fpm-1 | 172.18.0.3 - 18/Jan/2022:20:00:20 +0000 "GET /index.php" 200
docker-compose-nginx-phpfpm-web-1 | 2022/01/18 20:00:20 [error] 32#32: *18 FastCGI sent in stderr: "PHP message: test" while reading response header from upstream, client: 172.18.0.1, server: phpfpm.local, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.2:9000", host: "localhost:8080"
For clarity:
PHP Container Log
docker-compose-nginx-phpfpm-php-fpm-1 | NOTICE: PHP message: test
Nginx container log
docker-compose-nginx-phpfpm-web-1 | 2022/01/18 20:00:20 [error] 32#32: *18 FastCGI sent in stderr: "PHP message: test" while reading response header from upstream, client: 172.18.0.1, server: phpfpm.local, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.2:9000", host: "localhost:8080"
What's going on here? is this expected behaviour?
This is the result of a very basic and standard php-fpm/nginx setup with a docker-compose.yml like this:
version: "3.9"
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./default.conf:/etc/nginx/conf.d/default.conf
links:
- php-fpm
php-fpm:
image: php:8-fpm
volumes:
- ./src:/var/www/html
a default.conf like:
server {
index index.php index.html;
server_name phpfpm.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
and an index.php like:
<?php
ini_set('display_errors', 'off');
ini_set('error_log', '/dev/stdout');
error_log('test');
echo phpinfo();