6

I keep seeing logs like these in my Kubernetes cluster:

[php] - -  05/Jul/2020:20:15:55 +0000 "POST /api/bookings" 200

How can I disable them?

If PHP wants to write an error or something, I want to keep that, it's just the request logs I don't care about (NGINX will log them a 2nd time anyway).

I'm using php:7.1-fpm

1
  • which docker image are you using? please provide more informations like if you are using a custom image
    – c4f4t0r
    Jul 5, 2020 at 21:12

3 Answers 3

6

It depends on linux distributive, e.g. on CentOS you can find config file in derectory /etc/php-fpm.d and disable logging by editing several vars like access.log , php_admin_flag[log_errors], maybe more (depends of php version).

5
  • 1
    access.log! That's the one. perl -pi -e 's#^(?=access\.log\b)#;#' /usr/local/etc/php-fpm.d/docker.conf fixes it. Thank you
    – mpen
    Jul 5, 2020 at 22:18
  • Please mark the answer as solution if this really helps
    – Doka
    Jul 6, 2020 at 8:01
  • what value are you supposed to set the access.log to make it stop logging? Dec 2, 2020 at 8:41
  • Reference to docs: php.net/manual/en/install.fpm.configuration.php
    – Joe Niland
    May 12, 2021 at 1:20
  • 1
    @JoelHarkes Just comment it out. My little perl one-liner puts a ; in front of it to do that. I suspect you could also set it to an empty string, but I haven't tried. Or maybe /dev/null if that doesn't work.
    – mpen
    Aug 3, 2021 at 20:49
5

set

access.log = /dev/null

in your php-fpm conf file. In my example /etc/php-fpm.d/www.conf

or for docker file:

RUN echo "access.log = /dev/null" >> /usr/local/etc/php-fpm.d/www.conf
2

Thanks for the help, but I needed to make it better.

In the docker container I found access.log in several places.

root@8f03d2e7056f:/var/www/html# grep -r 'access.log' /usr/local/etc/
/usr/local/etc/php-fpm.d/www.conf.default:; - 'access.log'
/usr/local/etc/php-fpm.d/www.conf.default:; The access log file
/usr/local/etc/php-fpm.d/www.conf.default:;access.log = log/$pool.access.log
/usr/local/etc/php-fpm.d/www.conf.default:; The access log format.
/usr/local/etc/php-fpm.d/docker.conf:access.log = /proc/self/fd/2
/usr/local/etc/php-fpm.d/www.conf:; - 'access.log'
/usr/local/etc/php-fpm.d/www.conf:; The access log file
/usr/local/etc/php-fpm.d/www.conf:;access.log = log/$pool.access.log
/usr/local/etc/php-fpm.d/www.conf:; The access log format.
root@8f03d2e7056f:/var/www/html#

I'm especially interested in the docker.conf file

root@8f03d2e7056f:/var/www/html# cat /usr/local/etc/php-fpm.d/docker.conf
[global]
error_log = /proc/self/fd/2

; https://github.com/docker-library/php/pull/725#issuecomment-443540114
log_limit = 8192

[www]
; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2

clear_env = no

; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes
decorate_workers_output = no
root@8f03d2e7056f:/var/www/html#

And the result is a line to dockerfile

RUN sed -i 's/access.log = \/proc\/self\/fd\/2/access.log = \/proc\/self\/fd\/1/g' /usr/local/etc/php-fpm.d/docker.conf

Good luck

1
  • 1
    N.B. that www.conf.default isn't included, and lines that start with ; are already commented out. The only real config there is /usr/local/etc/php-fpm.d/docker.conf:access.log. You can fix your grep/sed by putting a ^ at the start to weed out the commented-out lines.
    – mpen
    Aug 3, 2021 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .