Not able to see STDERR Output with docker

Not able to see STDERR Output with docker

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

Stefan Bogdanescu

Founder & Senior Architect

Why Your PHP Errors Disappear in Docker Logs

When you configure an Apache-based PHP container to stream logs, you typically rely on symbolic links to merge file descriptors. The standard pattern involves creating a symlink for access.log pointing to /dev/stdout and error.log pointing to /dev/stderr. Once these links are established, the application logic runs in the foreground or via docker run, and you expect to see both successful requests and exceptions in your Docker Compose logs.

However, a common point of failure occurs when standard PHP runtime errors—like calling an undefined function or missing a required class—fail to appear in the stream, even though custom logging calls like error_log() work perfectly. This discrepancy often leads developers to assume the container configuration is broken, when in reality, the issue lies within the PHP interpreter's internal state management rather than the Docker file descriptor mapping.

The root cause is a misunderstanding of how PHP handles logging by default versus when it needs explicit configuration. In many lightweight PHP images, such as the older php:5.6-apache stack, the default behavior for uncaught exceptions and fatal errors is to write them to the system's standard error stream only if specific directives are enabled. Without these flags, PHP suppresses these messages or directs them to a file that isn't being monitored by your container orchestration.

To resolve this, you must explicitly enable error logging within the PHP configuration file. You need to create or modify a php.ini file located at /usr/local/etc/php/ inside the container and add the following directives:

log_errors = On
error_log = /var/log/apache2/error.log

The first directive, log_errors = On, instructs the PHP engine to capture all error messages (E_ALL) rather than suppressing them. The second directive, error_log, defines the destination path. Because you have already symlinked /var/log/apache2/error.log to /dev/stderr, writing to this file automatically pushes the data to the Docker standard error stream.

Once these lines are added, you must restart the container for the changes to take effect. The Apache process typically reads php.ini at startup, so a simple reload of the web server might not be sufficient; a full container restart ensures the new configuration is loaded into memory. After restarting, any fatal errors or uncaught exceptions will trigger the logging mechanism, and you will see them immediately in your Docker log output alongside your application's standard output.

This setup highlights a critical trade-off in PHP development environments. Relying solely on error_log() functions for debugging can be misleading because they bypass PHP's internal error reporting system. If a script crashes due to a syntax error or a fatal function call before any user code runs, those messages depend entirely on the php.ini settings. Neglecting these configurations creates a blind spot where critical failures are invisible until you inspect the logs manually or add verbose debugging elsewhere.

For modern deployments using Laravel or similar frameworks, this distinction remains vital. While newer PHP versions and orchestration tools often have better defaults, explicitly defining error handling strategies prevents unexpected behavior in production. If you are managing multiple containers or scaling your application, ensuring consistent php.ini configurations across instances is essential for reliable observability.

For developers looking to streamline their logging infrastructure further, resources like https://laravelcompany.com offer insights into best practices for maintaining clean separation between application logs and system-level error streams in containerized environments.

Our network