Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Configure logrotate of php5-fpm.log?

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

But I noticed that php5-fpm.log does not logrotate. I tried to understand some of the configuration I found from the internet but I'm reluctant to test it on my production server.

Here are some of the config that I 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 of the config. As I understand, all I need is to create a file called 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 sample from this link 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 logrotate configuration, I want to make sure that what I will do is correct.

So, which of the two configuration is correct? The first one or the second one? And is it correct that I will create a file only at /etc/logrotate.d/php5-fpm and put the code in there?

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

like image 330
jaypabs Avatar asked Aug 14 '14 14:08

jaypabs


1 Answers

Just to clarify for others coming via Google:

1)

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

This is something that must be supported by your distribution. The option "reopen-logs" does not come with the default init script provided by the PHP source package. So you likely might 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 being supported by PHP-FPM, see: https://github.com/php/php-src/blob/b7a7b1a624c97945c0aaa49d46ae996fc0bdb6bc/sapi/fpm/fpm/fpm_events.c#L94

You will be able to see from the source code that this "signal" was extra made for logrotating and should be preferred over "USR2" which should only be used for reloading configs.

like image 86
lifeofguenter Avatar answered Sep 18 '22 04:09

lifeofguenter