4

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

mpen
  • 313
  • 5
  • 14
  • which docker image are you using? please provide more informations like if you are using a custom image – c4f4t0r Jul 05 '20 at 21:12

3 Answers3

4

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).

Doka
  • 56
  • 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 05 '20 at 22:18
  • Please mark the answer as solution if this really helps – Doka Jul 06 '20 at 08:01
  • what value are you supposed to set the `access.log` to make it stop logging? – Joel Harkes Dec 02 '20 at 08:41
  • Reference to docs: https://www.php.net/manual/en/install.fpm.configuration.php – Joe Niland May 12 '21 at 01:20
  • @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 03 '21 at 20:49
4

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
dervill
  • 41
  • 1
1

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

spirit0007
  • 11
  • 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 03 '21 at 20:53