I have php-fpm in a docker container and in the Dockerfile I edit the fpm config file (/etc/php5/fpm/pool.d/www.conf) to set up access logs to go to /var/log/fpm-access.log and error logs to go to /var/log/fpm-php.www.log:

# Do some php-fpm config
#  Redirect worker stdout and stderr into main error log
#  Activate the fpm access log
#  Enable display errors
#  Enable the error log
RUN sed -i '/^;catch_workers_output/ccatch_workers_output = yes' /etc/php5/fpm/pool.d/www.conf && \
    sed -i '/^;access.log/caccess.log = /var/log/fpm-access.log' /etc/php5/fpm/pool.d/www.conf && \
    sed -i '/^;php_flag\[display_errors\]/cphp_flag[display_errors] = off' /etc/php5/fpm/pool.d/www.conf && \
    sed -i '/^;php_admin_value\[error_log\]/cphp_admin_value[error_log] = /var/log/fpm-php.www.log' /etc/php5/fpm/pool.d/www.conf && \
    sed -i '/^;php_admin_flag\[log_errors\]/cphp_admin_flag[log_errors] = on' /etc/php5/fpm/pool.d/www.conf

This works fine - I can get a shell into the container to see the logs. But... it is not best-practice.

The problem is when I try to use the docker log collector - I need php-fpm to log to stdout or stderr so docker can capture them and provide them to the docker logs command.

I tried to do this in the Dockerfile (which is a idea I copied from the official nginx docker image):

# Redirect fpm logs to stdout and stderr so they are forwarded to the docker log collector
RUN ln -sf /dev/stdout /var/log/fpm-access.log && \
    ln -sf /dev/stderr /var/log/fpm-php.www.log

This is not working - no access logs are seen from docker logs - I'm trying to figure out why? Did anyone else that uses fpm in docker manage to get logging working to the docker log collector?


Ok, the way to do this is to send the error and the access logs to the following address:


In php5-fpm.log add:

access.log = /proc/self/fd/2
error_log = /proc/self/fd/2

NOTE: access.log is correct, find in this page https://www.php.net/manual/en/install.fpm.configuration.php

  • It's possible for there to be /dev/stdin ~ /dev/fd/0 ~ /proc/self/fd/0, and /dev/stdout and /dev/stderr variants. Might be easier to remember to use /dev/stdin. Dec 1 '15 at 7:22
  • 2
    There's an error in the answer - it's "access_log" not "access.log"
    – rfay
    Mar 27 '18 at 21:19
  • 5
    It appears that it is access.log: github.com/docker-library/php/blob/…
    – CommandZ
    Jul 6 '18 at 17:38

Note that the baked in fpm config for the latest version of the official PHP fpm docker image writes to the standard streams:

error_log = /proc/self/fd/2


; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2
  • Thanks, that's interesting. I didn't know that there's a official image now
    – Tom
    Jan 13 '16 at 17:25
  • 3
    Which docker image are you referring to? I ran php:7-fpm and it doesn't appear to be logging errors to stderr.
    – Derek
    May 15 '19 at 12:06
  • If you run php-fpm inside a container it should report what error_log value is. In my case it's /proc/self/fd/2 as needed. Docker image php:7.2-fpm.
    – laimison
    Apr 11 '20 at 19:35

PHP-FPM logs will only appear in STDERR - so you can symlink the fpm.log to /dev/stderr if you want.

ln -sf /dev/stderr /var/log/fpm-access.log
ln -sf /dev/stderr /var/log/fpm-error.log
  • 4
    This solution was given in the question and the asker stated it didn't work. Maybe you can specify how he can load it in his dockerfile to make it work properly or other diagnostics he can perform on his container? Dec 18 '15 at 3:11
  • @AndrewDomaszek file names are different
    – funder7
    Nov 1 '20 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.