FreeBSD's Apache HTTPD port does not ship with configuration for the FreeBSD log rotation utility (newsyslog), so your logs won't be rotated by default.

---
title: Rotating Apache httpd Log Files on FreeBSD
author: Mikkel Hogh
date: 08 Oct 2009
source: http://mikkel.hoegh.org/2009/10/08/rotating-apache-httpd-logfiles-freebsd/
---

With the disk space available on modern servers, you tend to notice some things
a lot less. Like the boring fact that without log rotation, an Apache access log
can grow to gigabyte size in no time.

FreeBSD's Apache HTTPD port does not ship with configuration for the FreeBSD log
rotation utility, `newsyslog`, so your logs won't be rotated by default.

That, however, is fairly easy to fix by tweaking /etc/ [newsyslog.conf][1] a bit.

**Here's how I did it:**

    /var/log/httpd-access.log www:www 440 9 * $W1D4 J /var/run/httpd.pid 30
    /var/log/httpd-error.log  www:www 440 9 * $W1D4 J /var/run/httpd.pid 30

**Broken up, this means:**

1. `/var/log/httpd-access.log`: Name of the log file we're rotating
2. `www:www` set user and group ownership of the archived logs to www, so
   sysadmins can read them.
3. `440` set the archive files to be read-only for the www user and group and no
   access for anyone else.
4. `9` keep nine archived log files excluding the current one. This way, we
   should always have the latest 10 weeks of log data available.
5. `*` don't rotate based on log file size.
6. `$W1D4` rotate logs every Monday at 4 in the morning.
7. `J` compress the archived logs with bzip2.
8. `/var/run/httpd.pid` -- get the process ID for the httpd server here.
9. `30` send `SIGUSR1` to cause a [graceful restart of httpd][2].

I set this up last week, and it has since done its work, turning my 1GiB
`/var/log/httpd-access.log` into a 46MiB `httpd-access.log.0.bz2`. Log files are
some of the best use cases for compression. Enjoy.

[1]: http://www.freebsd.org/cgi/man.cgi?query=newsyslog.conf&sektion=5
[2]: http://httpd.apache.org/docs/2.2/stopping.html#graceful