I’m developing a wordpress site with docker. I need to write php code, so I want to see my php errors with apache error logs.
In a non docker environment I would do something like this:
tail -100f /var/log/apache2/error.log
With docker scenario, if I log in my apache container my apache logs are old and empty:
$ docker exec -t -i apache /bin/bash
root@d47b168d8c4b:/var/www/html# cd /var/log/apache2/
root@d47b168d8c4b:/var/log/apache2# ls -alrt
total 8
-rw-r----- 1 www-data www-data 0 Apr 30 04:34 other_vhosts_access.log
-rw-r----- 1 www-data www-data 0 Apr 30 04:34 error.log
-rw-r----- 1 www-data www-data 0 Apr 30 04:34 access.log
drwxr-x--- 2 www-data www-data 4096 Apr 30 04:34 .
drwxr-xr-x 11 root root 4096 Apr 30 05:58 ..
root@d47b168d8c4b:/var/log/apache2#
Maybe logs are in a different place so I go to apache virtual hosts configuration and sites-enabled folder is empty!
In sites-availabe I have this configuration:
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
where ${APACHE_LOG_DIR} is /var/www/apache2
My wordpress image is the official one: https://registry.hub.docker.com/_/wordpress/
I look at the dockerfile searching for hints but I saw no configuration related. It’s based on FROM php:5.6-apache so I look also that dockerfile but I don’t get any log configuration there.
Currently this is the only way I can get logs:
docker logs apache
Where apache is my container-name. However I only get apache access-logs, I don’t get any error logs
I had the same issue. To fix this, I added a php config that turns on log_errors and specifies an error_log location.
For example:
You will also need to create the php_err.log file and set appropriate permissions:
Here’s a Dockerfile that does this: