Apache / PHP error_log location in Docker
Asked Answered
A

3

16

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?

Abalone answered 17/3, 2019 at 12:51 Comment(1)
Related, for locating the PHP error log: Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel) (despite the over-specific title).Feucht
A
23

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
Applewhite answered 17/3, 2019 at 12:58 Comment(2)
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 500Magog
@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.Abalone
C
4

To only see PHP logs, try:

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

To see all logs, try:

docker logs -f [containerName]
Cultivar answered 23/7, 2020 at 11:49 Comment(1)
What is the point of leaving out the verbs?Feucht
M
0

Running Apache2 in the docker-compose.yml as foreground process did make the logging work.

entrypoint: ["/bin/bash", "-c", "apachectl -D FOREGROUND"]

This does not require to enable logging and redirecting in the php.ini file using the fpm8-3:apache docker image.

Munos answered 15/2 at 14:0 Comment(2)
Is there a way to make the logging working for an running container?Ramiah
@Ramiah I do not think so, because only running as foreground process and not as service enables the apache2 logging into logfiles - at least with that image.Munos

© 2022 - 2024 — McMap. All rights reserved.