Using apache + php-fpm containers in docker-compose, I can't get the php-fpm container to display any errors.
docker-compose.yml
version: '3'
services:
php:
build:
context: ./php
ports:
- 9000:9000
volumes:
- ./code:/code
- ./php/www.conf:/usr/local/etc/php-fpm.d/www.conf
environment:
ENVIRONMENT: local
web:
image: httpd:2.4
depends_on:
- php
ports:
- 80:80
volumes:
- ./code:/usr/local/apache2/htdocs
- ./web/httpd.conf:/usr/local/apache2/conf/httpd.conf
depends_on:
- php
php-fpm Dockerfile:
FROM php:5.6-fpm
php-fpm www.conf:
[global]
error_log = /proc/self/fd/2
[www]
user = www-data
group = www-data
listen = nginx:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
; Logging
; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2
clear_env = no
; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes
php_flag[display_errors] = on
php_admin_flag[log_errors] = on
;php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_value[error_reporting] = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED
php_admin_value[display_startup_errors] = on
docker-compose logs only shows php-fpm access logs, no error logs.
Tried all solutions proposed in post proposed as possible duplicate: PHP-FPM doesn't write to error log None of them worked for me, check my comments down below.
In my case it was the /usr/local/etc/php-fpm.d/docker.conf which caused the troubles:
[global]
error_log = /proc/self/fd/2
; https://github.com/docker-library/php/pull/725#issuecomment-443540114
log_limit = 8192
[www]
; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2
clear_env = no
; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes
decorate_workers_output = no
The error_log directive's value of /proc/self/fd/2 causes the log being written into the terminal/console where the docker-compose up is running.
I just had to create a custom global fpm config file within the /usr/local/etc/php-fpm.d/ directory and make it execute as the last one by naming it zz-global.conf, so it can override the docker.conf values. Then I just needed to set the value for the error_log to a custom path within the php-fpm container e.g.:
[global]
error_log = /var/www/logs/php-fpm-error.log
That's it.
Maybe worth mentioning: my php.ini (modified php.ini-development) has following custom error logging related values:
; https://stackoverflow.com/a/10546138/4721232
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Default Value: no
catch_workers_output = yes
php_admin_flag[log_errors] = on
php_admin_flag[display_errors] = on
php_admin_value[error_reporting] = E_ALL
php_admin_value[error_log] = /var/log/error.log
access.log = /var/www/logs/php-fpm-access.log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With