Apache Rotate Logs and Log Rotate.

David Robillard david.robillard at gmail.com
Thu Feb 15 18:24:19 UTC 2007

> I have Apache making separate log files for each of my virtual hosts and
> putting them in /home/vhostname/log. Rotate logs makes a new log every
> 24 hours, but the logs quickly add up and since the sites are fairly
> busy the logs are at times over 5gigs. Is there any way to make rotate
> logs delete the log files after two days? Someone recommended me Log
> Rotate (from the ports tree), but this program does basically what
> Rotate logs does; except it makes things more complicated because it
> needs to restart apache and such. Is there a easy way to just have
> Apache's rotatelogs rotate the logs and then delete them after two days?
> Any feedback, suggestions, or comments would be greatly appreciated.

Hi Peter,

I personaly don't use neither Log Rotate nor Rotate Logs, but
configure newsyslog.conf(5) to handle the job of Apache log rotation
and clean-up.

The newsyslog software is part of FreeBSD's base system, so you don't
need to install anything. Just configure /etc/newsyslog.conf and
that's it. No need to restart anything because newsyslog is already
active in FreeBSD's base system via /etc/crontab. It can rotate the
logs, compress them with either gzip(1) or bzip2(1) and remove the old
ones to preserve disk space.

For example, let's say you have two virtual host's logs into
/home/vhostname1/log and /home/vhostname2/log, you can configure
newsyslog to:

a) Keep only 10 log files. Remove the older ones as they grow. (i.e.
10 in the config below)
b) Create files with chmod 640 and owner root:www (i.e. root:www and 640)
c) Rotate the files when they reach 1Mb in size. (i.e. 1048576)
d) Compress the files with gzip(1) to preserve compatibility with
webalizer. (i.e. Z)

# logfilename          [owner:group]    mode count size when  flags
[/pid_file] [sig_num]

# Host vhostname1.
/home/vhostname1/log/access.log  root:www    640 10 1048576 * Z
/home/vhostname1/log/error.log      root:www    640 10 1048576 * Z

# Host vhostname2.
/home/vhostname2/log/access.log  root:www    640 10 1048576 * Z
/home/vhostname2/log/error.log      root:www    640 10 1048576 * Z

Check the man pages for newsyslog(8) and newsyslog.conf(8) for more information.

I've been using this for more then two years now and it works like a charm.


David Robillard
UNIX systems administrator & Oracle DBA
CISSP, RHCE & Sun Certified Security Administrator
Montreal: +1 514 966 0122

More information about the freebsd-questions mailing list