Apache Log Rotation Cronolog

Apache doesn’t support log rotation but you can use a program called cronolog to handle it for you. Install and configuration only takes a minute.

Cronolog Setup

  1. Get in to the console. (Ctrl+Alt+T in Ubuntu)
  2. sudo apt-get install cronolog

Apache Configuration

  1. Find the config file for which you’re setting up log rotation. For me, I was setting up a virtual server so my config file was located in /etc/apache2/conf.d/example-site.conf. The default web site in an Apache install is in /etc/apache2/apache2.conf
  2. Edit that config file. sudo vi /etc/apache2/conf.d/example-site.conf
  3. Find your CustomLog and ErrorLog settings or add them.
  4. Add “|/usr/bin/cronolog ” in front of the path in those settings. My settings looked liked the following when I was done:

CustomLog “|/usr/bin/cronolog¬†/path/to/example-site/logs/%Y_%m_%d.log” combined
ErrorLog “|/usr/bin/cronolog¬†/path/to/example-site/logs/%Y_%m_%d.err”

You’ll need to restart Apache by doing sudo service apache2 restart.

The %Y, %m and %d are arguments that Cronolog will use to rotate your logs and they mean year, month and day respectively. In this scenario Cronolog will rotate the log every day and create files like 2012_06_10.log, 2012_06_11.log, etc.

Coding, Linux Admin, etc.