13

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,738
  • 21
  • 105
  • 131
IMB
  • 15,163
  • 19
  • 82
  • 140
  • 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

21

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,738
  • 21
  • 105
  • 131
Mostafa Hussein
  • 11,063
  • 3
  • 36
  • 61
  • 15
    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
  • @DanielFanica I came across this issue again and encoutered something similar to that "pretty useless" logs. In my case my `vhost.conf` is causing issues because of a custom log directive that has no Docker volume. Basically, just make sure logs in `vhost.conf` has no issues first so PHP can properly log in `stderr`. – IMB Nov 24 '22 at 23:40
4

To only see PHP logs, try:

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

To see all logs, try:

docker logs -f [containerName]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jean
  • 41
  • 4