Finding the PHP error log inside a Docker container
docker logs shows nothing while the PHP page is blank or returns an errorShort 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.
Fix it fast
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"));'2Match what you see, then jump to its fix
- 1
error_log is empty and log_errors is onErrors go to the container's output, so you read them with docker logsFix - 2
log_errors prints as an empty string or 0log_errors is off, so nothing is written anywhereFix - 3
error_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
The browser shows a blank page or a generic 500, and display_errors is emptyErrors are hidden from the page because display_errors is offFix
- 1
What does the error look like?
docker logs shows nothing while the PHP page is blank or returns an errorAccess php error logs in Dockererror_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 php3Verify
Trigger the failing request again and watch the new line appear.
docker logs --follow --tail 0 my-phpConfirmed by docs.docker.com
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_ALL3Verify
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
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.log2Fix
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/php3Verify
Cause an error and check the file on the host.
tail -n 20 ./logs/errors.logConfirmed by php.net
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 = On3Verify
Reload the page; the message shows in the browser and in docker logs.
docker logs --tail 20 my-phpConfirmed by php.net
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
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 fixBack end
docker build stops at RUN composer install with exit code 1
Allowed memory size of ... bytes exhausted
Exit code 1 only says the RUN step failed.
4 causes, each with a fixBack end
memory_limit does not change inside a PHP Docker container
memory_limit is still 128M after editing php.ini in the container
Your setting is being read from the wrong place or overridden.
4 causes, each with a fixBack end
php artisan serve starts but the app is not reachable, or the .env is ignored
Server stops right after start with a non-zero exit code when --port is given and the port is busy
php artisan serve listens on 127.0.0.1 port 8000 by default.
4 causes, each with a fixBack end
Guzzle or Http::get fails with cURL error 6 in Laravel
Illuminate\Http\Client\ConnectionException: cURL error 6: Could not resolve host
cURL error 6 means the machine running PHP could not turn the host name in the URL into an IP address.
3 causes, each with a fixBack end
Laravel cannot find the database host: getaddrinfo failed
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed
The message means PHP could not turn DB_HOST into an IP address.
3 causes, each with a fix