No php-fpm error logs from docker container

No php-fpm error logs from docker container

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

No php-fpm error logs from docker container

When deploying a stack with Apache and PHP-FPM in Docker, one of the most frustrating issues is finding that your PHP-FPM worker processes appear completely silent on errors. You might see 500 Internal Server Error responses in your browser, but when you inspect the php container logs using docker-compose logs php, the only output you get is access logs or nothing at all. This specific silence often stems from how the logging streams are configured within the PHP-FPM worker pool and how Docker captures stdout versus stderr.

In the configuration provided, the critical line is set to write errors to /proc/self/fd/2. In a standard Linux process, file descriptor 2 represents stderr, so this setting seems correct. However, when running inside Docker, the behavior of file descriptors changes slightly depending on how the container is started and how Apache connects to PHP-FPM via Unix sockets or TCP. If you are connecting via TCP (as suggested by listen = nginx:9000 in your config, though your stack uses Apache), the connection might not be routing the stderr stream correctly to Docker's log driver unless explicitly handled.

The core of the problem usually lies in the interaction between PHP-FPM's internal logging and the container's stdout/stderr streams. Even with catch_workers_output = yes enabled, which attempts to redirect worker output to the main error log, simply setting error_log to /proc/self/fd/2 does not guarantee that Docker will capture those bytes if the file descriptor is not being flushed or managed correctly by the PHP process itself.

To resolve this without relying on external logging drivers like fluentd or complex sidecars, you need to ensure that PHP-FPM writes directly to a persistent file within the container's writable layer. This is a common trade-off: writing to a file ensures persistence and visibility in Docker logs, whereas writing to stdout/stderr relies on the application server (Apache) forwarding those signals correctly, which can be finicky across different versions of Apache and PHP-FPM.

Modify your www.conf to use a file path instead of /proc/self/fd/2. Replace the error log directive with a static path:

[global]
error_log = /var/log/php-fpm/www-error.log
access.log = /var/log/php-fpm/www-access.log

Update your docker-compose.yml to mount this directory so you can access the logs from your host machine if needed, and ensure the container has write permissions for /var/log:

volumes:
  - ./code:/code
  - ./php/www.conf:/usr/local/etc/php-fpm.d/www.conf
  - ./php/logs:/var/log/php-fpm

Additionally, verify that your Apache configuration is not inadvertently suppressing these errors. While PHP-FPM handles its own error logging, Apache might have ErrorLog directives pointing to different locations or levels that mask underlying issues. Ensure your Apache virtual host includes the correct ProxyPassMatch and ProxyPassReverse directives if using reverse proxying, but for direct socket communication, focus on the PHP side first.

Another potential pitfall involves the PHP configuration inside the container. The line php_admin_value[error_reporting] = E_ALL & ~E_NOTICE... suppresses certain error levels. If your application throws a fatal error that you expect to see, ensure it isn't being filtered out by this directive. For debugging purposes, temporarily set display_errors to on and log_errors to on without suppressing specific error types until you have identified the issue.

If you are using PHP 5.6 as shown in your Dockerfile, be aware that this version is end-of-life and lacks many modern logging enhancements available in PHP 7.4 or 8.x. Upgrading the base image to a supported LTS version (e.g., php:8.2-fpm) often resolves obscure logging bugs related to stream handling.

By switching from /proc/self/fd/2 to a concrete file path and ensuring volume mounts for log directories, you give Docker a reliable source of truth for PHP-FPM errors. This approach bypasses the complexities of stream redirection in containerized environments and provides immediate visibility into configuration mistakes, missing dependencies, or runtime exceptions that would otherwise remain hidden.

Our network