How to configure logrotate for php5-fpm.log?

I enabled error_log = /var/log/php5-fpm.log under /etc/php5/fpm/php-fpm.conf on my ubuntu 12.04 with nginx and php5-fpm running.

But I noticed that php5-fpm.log is not freezing. I tried to understand some of the settings that I found from the Internet, but I do not want to test them on my production server.

Here are some of the configurations found:

 /var/log/php5-fpm.log { rotate 12 weekly missingok notifempty compress delaycompress postrotate invoke-rc.d php5-fpm reopen-logs > /dev/null endscript } 

This is the link in the config. As far as I understand, I only need to create a file under php5-fpm under /etc/logrotate.d/ , so it will look like /etc/logrotate.d/php5-fpm and with the above code.

I also found another example from this with the following code:

  /var/log/php5-fpm.log { daily missingok rotate 52 compress delaycompress notifempty create 640 root adm sharedscripts postrotate [ ! -f /var/run/php5-fpm.pid ] || kill -USR1 `cat /var/run/php5-fpm.pid` endscript } 

Since I'm new to setting up logrotate, I want to make sure I do the right thing.

So which of the two configurations is correct? First or second? And is it right that I only create the file in /etc/logrotate.d/php5-fpm and put the code there?

Sorry if this is a newbie question, I just can't find a complete explanation of how to do this.

+5
source share
1 answer

Just to clarify that others come through Google:

1)

 invoke-rc.d php5-fpm reopen-logs > /dev/null 

This is what should be supported by your distribution. The "reopen-logs" option has no , with a default initialization script provided by the PHP source package. You may not be able to use this.

2)

 [ ! -f /var/run/php5-fpm.pid ] || kill -USR1 `cat /var/run/php5-fpm.pid` 

This is the correct option and also officially supported by PHP-FPM, see https://github.com/php/php-src/blob/b7a7b1a624c97945c0aaa49d46ae996fc0bdb6bc/sapi/fpm/fpm/fpm_events.c#L94

You can see from the source code that this "signal" was additionally executed for log rotation and should be preferable to "USR2", which should only be used to reload configurations.

+6
source

Source: https://habr.com/ru/post/1200327/


All Articles