Reputation: 2006
I'm running a php docker image (php:5.6-apache) which has apache's error and access logs redirected to STDERR and STDOUT respectively using symbolic links.
When I run the docker image in the foreground or access the docker container logs, I can see the STDOUT output. But I don't see any errors (even when I generate php errors).
Any idea why that is and how I can fix it?
I'm running docker for Mac (but I don't think this makes any difference)
Thanks
access.log -> /dev/stdout
error.log -> /dev/stderr
other_vhosts_access.log -> /dev/stdout
Edit / Solved:
As @BMitch mentions and proves below, the STDERR redirection works fine.
The problem was with PHP configuration. If I logged an error with error_log()
, it would get output to the log. But if I had a php error, like calling an undefined function, the error would never appear in the log. This seems a little inconsistent. In any case, ...
I had to create a php.ini
file in /usr/local/etc/php/
and add these two parameters:
log_errors = On
error_log = /var/log/apache2/error.log
and then restart the docker container. This caused all PHP errors to be logged and output to STDERR. See @German's answer for an example.
Upvotes: 24
Views: 44374
Reputation: 1705
If you want to see the php errors in the apache2 log you have to activate them. For this you have to write to the php.ini
file into the folder /usr/local/etc/php
.
I wrote an example in a repository so that the example can be seen.
https://github.com/nitzap/stackoverflow-docker-php-error-log
If you want to see the stdout and stderr logs, you can do it with the following command, outside of your containers:
docker logs <name_container>
Now if you want to remain attached in the log you can add the -f option as in the tail command.
docker logs <name_container> -f
Upvotes: 5
Reputation: 83
In my case I was missing this magic setting ("no" by default):
#/etc/php/7.0/fpm/pool.d/www.conf
catch_workers_output = yes
Found it here Symfony logs to stdout inside Docker container
Upvotes: 2
Reputation: 264611
I'm unable to reproduce your situation. If the below doesn't help, please provide an mcve of your error.
Basic Dockerfile:
$ cat Dockerfile
FROM php:5.6-apache
COPY . /var/www/html/
The only php is this file to generate an error:
$ cat error.php
<?
error_log("Hello error log.")
?>
Build and run it:
$ docker build -t test-php .
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM php:5.6-apache
---> f16436448ebd
Step 2/2 : COPY . /var/www/html/
---> Using cache
---> cfe66485e2cc
Successfully built cfe66485e2cc
Successfully tagged test-php:latest
$ docker run -p 8080:80 -d --name test-php test-php
7f9a1836a8157963966b583579dff94c6413292547b84d22957add77ad2d8e14
Curl is empty as expected, but calling it generates an error in the logs:
$ curl localhost:8080/error.php
Show stdout logs, redirecting error to /dev/null:
$ docker logs test-php 2>/dev/null
172.17.0.1 - - [31/May/2017:00:06:37 +0000] "GET /error.php HTTP/1.1" 200 174 "-" "curl/7.38.0"
Show stderr logs, redirecting stdout to /dev/null
$ docker logs test-php >/dev/null
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Wed May 31 00:06:25.064546 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.30 configured -- resuming normal operations
[Wed May 31 00:06:25.064584 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[Wed May 31 00:06:37.833470 2017] [:error] [pid 17] [client 172.17.0.1:50040] Hello error log.
Note the last line of the error output.
Upvotes: 15