Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache / PHP error_log location in Docker

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?

like image 578
IMB Avatar asked Mar 17 '19 12:03

IMB


People also ask

Where does PHP Error_log go?

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.

Where are PHP error logs Apache?

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 .

How do I enable PHP error logging?

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.


1 Answers

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
like image 174
Mostafa Hussein Avatar answered Sep 24 '22 03:09

Mostafa Hussein