Php: Not getting apache2 error logs

Created on 28 Nov 2015  路  14Comments  路  Source: docker-library/php

Hi guys,

When I do docker logs -f my_web_container which is running php:5.6-apache I'm only seeing access logs.

I've added a fatal error before any other code gets executed in my project in order to test, but I'm still only seeing access logs. In the browser, I do see the Fatal Error.

Any ideas as to why errors wouldn't be showing at all in the docker logs?

Most helpful comment

Recent builds have changed logging:

root@graves:~# ls -l /var/log/apache2/
total 0
lrwxrwxrwx 1 root root 11 Jul 29 21:49 access.log -> /dev/stdout
lrwxrwxrwx 1 root root 11 Jul 29 21:49 error.log -> /dev/stderr
lrwxrwxrwx 1 root root 11 Jul 29 21:49 other_vhosts_access.log -> /dev/stdout

My container actually runs supervisord which in turn runs apache2-foreground and some ancillary services. Sadly, docker logs for my container only shows the output of supervisord launching and there are no longer any logs from Apache hits (which I'm puzzled by).

All 14 comments

This is probably due to the default values of the following php options :

  • log_errors = Off
  • error_reporting = NULL

php:5.6-apache comes with no php.ini
so you should fill /usr/local/etc/php/php.ini (or /usr/local/etc/php/conf.d/errors.ini) with something like
log_errors = On
error_reporting = E_ALL
Then restart your container.

You should probably build an image with a custom php.ini.

I am also facing the same issue and not getting apache2's logs "access.log & error.log" inside the container.

I am using official PHP-Apache2 Image: https://github.com/docker-library/php/tree/master/7.0/apache

Any ideas how to resolve this?

use 'docker logs containerid'

@RichieSpence

I want to check the Apache2 error & access logs by going inside the Container.
at /var/log/apache2/error.log & access.log

in that case, you need to change apache2.conf or the site config (something like 000-default.conf) and set the error logs there.
Something like:
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

you can have this in your docker folder and then copy it over using the following in the dockerfile:
ADD yourcopy/000-default.conf /etc/apache2/sites-enabled/000-default.conf

@rnolan - I did the same thing but apache2 is not writing any logs into error.log and access.log.

APACHE_LOG_DIR is not currently available, but there is a PR to fix it: https://github.com/docker-library/php/pull/231

Recent builds have changed logging:

root@graves:~# ls -l /var/log/apache2/
total 0
lrwxrwxrwx 1 root root 11 Jul 29 21:49 access.log -> /dev/stdout
lrwxrwxrwx 1 root root 11 Jul 29 21:49 error.log -> /dev/stderr
lrwxrwxrwx 1 root root 11 Jul 29 21:49 other_vhosts_access.log -> /dev/stdout

My container actually runs supervisord which in turn runs apache2-foreground and some ancillary services. Sadly, docker logs for my container only shows the output of supervisord launching and there are no longer any logs from Apache hits (which I'm puzzled by).

check that 000-default site is enabled for your apache,
in my case /etc/apache2/sites-enabled/ does not contained softlink to 000-default.conf

so I ran

a2ensite 000-default
apache2ctl restart

then i started seeing logs in access.log and error.log

@Raaghu This still not working for me.

I'm seeing the logs just on the /dev/stdout like quoted above.

root@35dc665cf99d:/var/log/apache2# ls -lh
total 0
lrwxrwxrwx 1 root root 11 Jun 2 15:25 access.log -> /dev/stdout
lrwxrwxrwx 1 root root 11 Jun 2 15:25 error.log -> /dev/stderr
lrwxrwxrwx 1 root root 11 Apr 25 03:02 other_vhosts_access.log -> /dev/stdout

This way if I try to read the content of the file, I have no response.

If I run docker logs -f containerid I can see the logs, but I want this to the files?

Anyone have another idea to solve this?

@brito-gui
Looks like you are not using the offcial image of php-apache
I saw the softlinks created in DockerFile of ur image brito-gui/apache-php

For the supervisord issue, I can only recommend either removing the symlinks (and thus allowing Apache to log directly to the relevant files), or adjusting the symlinks to point to /proc/1/fd/1 instead (so that Apache attempts to log directly to supervisord's stdout).

Regardless, this image is working appropriately, and users looking for PHP errors should provide their own php.ini which adjusts the default settings (as described above).

I have apache2 running inside a docker container and it is writing logs to a location, but i want to write it to stdout, I have changed the location inside the apache config file still no logs are written to stdout.

Was this page helpful?
0 / 5 - 0 ratings