Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Finding the PHP error log inside a Docker container

Errordocker logs shows nothing while the PHP page is blank or returns an error

Short answer

PHP writes errors to the SAPI error logger when error_log is unset: stderr on the CLI, the web server's error log under Apache. In a container, read the output with docker logs. If nothing appears, log_errors is off, or error_log points at a file inside the container that you read with docker exec.

  • Applies to PHP 8.3, PHP 8.4, Docker Engine 27, Docker Compose 2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP inside the running container how it is configured to log. The three values tell you which cause below applies.

    docker exec my-php php -r 'var_dump(ini_get("log_errors"), ini_get("error_log"), ini_get("display_errors"));'
  2. 2Match what you see, then jump to its fix

    1. 1error_log is empty and log_errors is onErrors go to the container's output, so you read them with docker logsFix
    2. 2log_errors prints as an empty string or 0log_errors is off, so nothing is written anywhereFix
    3. 3error_log shows a path such as /var/log/php/errors.log, and docker logs stays quieterror_log points to a file inside the containerFix
    4. 4The browser shows a blank page or a generic 500, and display_errors is emptyErrors are hidden from the page because display_errors is offFix

What does the error look like?

  • docker logs shows nothing while the PHP page is blank or returns an error
  • Access php error logs in Docker
  • error_log file not found on the host

Cause 1 of 4

Errors go to the container's output, so you read them with docker logs

1Check

With error_log unset, PHP uses the SAPI error logger. That is an error log under Apache and stderr for the CLI. Docker collects a container's STDOUT and STDERR, so those messages end up in the container logs.

docker exec my-php php -r 'var_dump(ini_get("error_log"));'

2Fix

Read the container output. Follow it live, or ask for the last lines only.

docker logs --tail 50 my-php
docker logs --follow --since 10m my-php
# with Compose
docker compose logs --tail 50 php

3Verify

Trigger the failing request again and watch the new line appear.

docker logs --follow --tail 0 my-php

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 4

log_errors is off, so nothing is written anywhere

1Check

The PHP manual lists log_errors with a default of 0. The bundled php.ini-development and php.ini-production files are a starting point, but the official image ships neither as php.ini unless you copy one.

docker exec my-php php -r 'var_dump(ini_get("log_errors"));'

2Fix

Add a small ini file under conf.d in your Dockerfile. It is picked up on the next start.

# Dockerfile
COPY logging.ini /usr/local/etc/php/conf.d/logging.ini

# logging.ini
log_errors = On
error_reporting = E_ALL

3Verify

Rebuild, restart, and confirm the value inside the container.

docker compose up -d --build
docker exec my-php php -r 'var_dump(ini_get("log_errors"));'

Confirmed by php.net

Did this fix it?

Cause 3 of 4

error_log points to a file inside the container

1Check

When error_log names a file, PHP writes there and not to stderr. The file lives in the container's own filesystem, not on your host, and it must be writable by the user PHP runs as.

docker exec my-php php -r 'var_dump(ini_get("error_log"));'
docker exec my-php tail -n 30 /var/log/php/errors.log

2Fix

Either read the file with docker exec, mount its folder as a volume to read it from the host, or unset error_log so the errors return to docker logs.

# docker-compose.yml
services:
  php:
    volumes:
      - ./logs:/var/log/php

3Verify

Cause an error and check the file on the host.

tail -n 20 ./logs/errors.log

Confirmed by php.net

Did this fix it?

Cause 4 of 4

Errors are hidden from the page because display_errors is off

1Check

php.ini-production sets display_errors to Off, php.ini-development sets it On. The manual says displaying errors is for development and should never be used in production.

docker exec my-php php -r 'var_dump(ini_get("display_errors"));'

2Fix

Keep it off in production and read the log instead. For a local development container only, turn it on in the same conf.d file.

# dev-only logging.ini
display_errors = On
log_errors = On

3Verify

Reload the page; the message shows in the browser and in docker logs.

docker logs --tail 20 my-php

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Leave error_log unset in containers so errors go to docker logs, where a log driver can collect them.
  • Keep display_errors Off outside local development and log_errors On.
  • Put logging settings in a file under conf.d so they are part of the image and survive rebuilds.
  • If you do write a file, mount its folder as a volume so the log outlives the container.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.