My PHP script has an error. For example, this shows this on the screen:
Warning: require(/var/www/foo.php): failed to open stream:
Where can I find this in the logs?
I tried docker logs containerName
, but it only shows access logs. E.g.,
192.168.2.1 - - [17/Mar/2019:10:00:00 +0000] "GET / HTTP/1.1" 200 505 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64)...
It doesn't show the PHP error above.
Going in the Apache logs folder inside the container via docker exec
shows the following:
ls -hltra /var/log/apache2
total 0
lrwxrwxrwx. 1 www-data www-data 11 Feb 6 04:42 other_vhosts_access.log -> /dev/stdout
lrwxrwxrwx. 1 www-data www-data 11 Feb 6 04:42 error.log -> /dev/stderr
lrwxrwxrwx. 1 www-data www-data 11 Feb 6 04:42 access.log -> /dev/stdout
I'm not even sure if this is where the PHP logs are at, but I can't view them.
Where can I find the Apache/PHP error logs in Docker?
The location of the error log file itself can be set manually in the php. ini file. On a Windows server, in IIS, it may be something like "'error_log = C:\log_files\php_errors. log'" in Linux it may be a value of "'/var/log/php_errors.
If you have build Apache and PHP from source, then the error logs by default is generated at your ${Apache install dir}/logs/error_log , i.e., generally /usr/local/apache2/logs/error_log .
Enable Error Logging in php. If you want to enable PHP error logging in individual files, add this code at the top of the PHP file. ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); Now, you must enable only one statement to parse the log errors in the php.
Ensure that you have the following inside php.ini
in order to be able to see the errors using docker logs -f containerName
as in general, sending the logs to /dev/stdout
and /dev/stderr
makes you able to receive it through docker logs
:
log_errors = On
error_log = /dev/stderr
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