11

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?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
IMB
  • 13,681
  • 17
  • 70
  • 124
  • Related, for locating the PHP error log: *[Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel)](https://stackoverflow.com/questions/5127838/)* (despite the over-specific title). – Peter Mortensen Sep 26 '21 at 22:21

2 Answers2

18

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
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Mostafa Hussein
  • 9,882
  • 3
  • 33
  • 57
  • 7
    this gets me something like this `[07/Oct/2021:21:55:51 +0000] "POST /sales-channel-api/v3/backinstock/subscribe HTTP/1.1" 500 831` ... pretty useless unless I can see what actually caused the 500 – Daniel Fanica Oct 07 '21 at 21:57
3

To only see PHP logs, try:

docker logs -f [containerName] >/dev/null

To see all logs, try:

docker logs -f [containerName]
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Jean
  • 31
  • 3