Developing php with docker

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:

Read More
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

Related posts

1 comment

  1. 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:

    # cat /usr/local/etc/php/conf.d/php_error.ini
    log_errors = on
    error_log = /var/log/apache2/php_err.log
    

    You will also need to create the php_err.log file and set appropriate permissions:

    touch /var/log/apache2/php_err.log
    chown www-data:www-data /var/log/apache2/php_err.log
    

    Here’s a Dockerfile that does this:

    FROM wordpress:latest
    MAINTAINER moo
    RUN touch /var/log/apache2/php_err.log && chown www-data:www-data /var/log/apache2/php_err.log
    COPY php_error.ini /usr/local/etc/php/conf.d/php_error.ini
    

Comments are closed.