Setting up logrotate for php error log

Avatar DBR 4 months ago

Hi, I'm using a LAMP stack with Ubuntu 16.04 and fastcgi/php7.0-fpm. I have logrotate set up across all my logs apart from one php error log (/var/log/php/error.log). My problem is that I'm not sure how to set up logrotate for this as I understand that I need to add a postrotate command to re-open the log after rotation or add copytruncate to the logrotate code.

Does php need to be reloaded by Apache? Should I just add the standard Apache pre- and postrotate commands?

if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi; \

and

if /etc/init.d/apache2 status > /dev/null ; then \
/etc/init.d/apache2 reload > /dev/null; \
fi;

or should I be running this:

/usr/lib/php/php7.0-fpm-reopenlogs

which contains this code:

#!/bin/sh
CONFFILE=/etc/php/7.0/fpm/php-fpm.conf
[ -r /etc/default/php7.0-fpm ] && . /etc/default/php7.0-fpm
CONF_PIDFILE=$(sed -n 's/^[[:space:]]*pid[[:space:]]*=[[:space:]]*//p' $CONFFILE)
PIDFILE=${CONF_PIDFILE:-/run/php/php7.0-fpm.pid}
[ -r "$PIDFILE" ] && kill -USR1 $(cat "$PIDFILE") > /dev/null
exit 0

as this is the default for another php log (/var/log/php7.0-fpm.log)?

Another possibility is to use rsyslog:

invoke-rc.d rsyslog rotate > /dev/null

At the moment, I think that this should work but I'm not certain:

/var/log/php/error.log {
weekly
copytruncate
missingok
notifempty
compress
delaycompress
postrotate
 invoke-rc.d rsyslog rotate > /dev/null
endscript
}

Any advice would be appreciated, many thanks.

EDIT: words…

0 Replies

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct