How to customize logrotate configuration for system php-fpm?

Created:

2017-03-02 08:58:50 UTC

Modified:

2017-08-08 13:45:56 UTC

0

Was this article helpful?


Have more questions?

Submit a request

How to customize logrotate configuration for system php-fpm?

Question

How to customize logrotate configuration for system php-fpm?

Answer

Modify the file /etc/logrotate.d/php-fpm so it looks like the following:

/var/log/php-fpm/*log {
    rotate 14
    daily
    missingok
    notifempty
    size 100M
    compress
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        /bin/kill -SIGUSR1 `cat /run/php-fpm/php-fpm.pid 2>/dev/null` 2>/dev/null || true
    endscript
}

Note: parameters rotate (specified in days), size and daily (or monthly, weekly) can be changed to meet the requirements.

If it is required to rotate log files more often, then remove parameter daily from the config above and create a cron task. For example, the following will run logrotate every 5 hours:

# crontab -e
01 01,06,11,16,21 * * *  /usr/sbin/logrotate /etc/logrotate.d/php-fpm -s /var/lib/logrotate/logrotate.status

Note: the information above is also applicable to other system log files.

Additional information can be found here: https://www.digitalocean.com/community/tutorials/how-to-manage-log-files-with-logrotate-on-ubuntu-12-10

Have more questions? Submit a request
Please sign in to leave a comment.