FreeBSD Apache Log Rotating

Posted on Saturday June 16th, 2018

An install of Apache from FreeBSD's pkg or /usr/ports will not configure any log rotation. However, it is possible to use newsyslog to achieve the task.

Newsyslog uses /etc/newsyslog.conf to specify files to rotate. The format is straight forward to understand with the exception of the flags and when. A suitable entry could be:

/www/log/access.log www:www 640 14 * @T00 Z /var/run/ 
/www/log/error.log  www:www 640 14 * @T00 Z /var/run/

These lines indicate (in order) the location of the file, the user:group to set the file, the permissions to set; the total number of files to keep (14); no size limit (*), rotate every midnight (@T00) and gzip the files (Z) followed by the pid file to use to send the process a SIGHUP.