Wednesday, May 04, 2011

Apache log rotation with FreeBSD

You know I wish that log rotation on FreeBSD came built in.  For example, install Apache, and the default log rotation is set up for you and ready to go...  A bit like Linux.

FreeBSD uses NewSysLog to rotate log files.

NewSysLog is installed and running by default on FreeBSD servers, so what you need to do is add your log files to /etc/newsyslog.conf

To rotate Apache log, add following files to end of /etc/newsyslog.conf
# Apache
/var/log/httpd-access.log               644  7     *    @T00  B     /var/run/ 30
/var/log/httpd-error.log                644  7     *    @T00  B     /var/run/ 30

To check out the options of this file:
man 5 newsyslog.conf

Run this to check everything is set up OK:
sudo newsyslog -v

You should then see:
/var/log/httpd-access.log <7>: --> will trim at Thu May  5 00:00:00 2011
/var/log/httpd-error.log <7>: --> will trim at Thu May  5 00:00:00 2011

Mostly from here: