Setting up logrotation with AWStats

By | March 26, 2008

One of the first things I did on my new server was setting up log rotation and AWStats. You may be wondering why. Well its easy, logs tend to grow. And I prefer to have a daily log for Apache projects, rather then one large file for the entire time of running.

Setting up the logrotation

By default most servers have this build in. It’s a program called logrotate, which is pretty handy. It consists out of one general configuration file (/etc/logrotate.conf) and several smaller ones (/etc/logrotate.d/*).

I have added my Apache log rotation configuration to the /etc/logrotate.d/Apache file. What you need to do is set how often and what location to perform the log rotation on. The second thing you can set is steps that must be performed before and after the log rotation, which will come in handy later on.

Add something similar to the following for each website:

/export/log/domain.com/*.log {
   daily
   missingok
   rotate 100
   compress
   notifempty
   create 640 root adm
   sharedscripts
   prerotate
      /usr/lib/cgi-bin/awstats.pl -config=domain -update
      cd /export/log/domain.com/
   endscript
}

These settings will rotate the log files once a day, saving up to 100 files maximum. The notifempty setting makes sure empty files never get rotated and missingok prevents the thing from crashing if files are missing. The part between prerotate and endscript I will explain a bit later on, so be patient.

The next step is setting up AWStats

Which should not be difficult as it can be done with:

apt-get install awstats

After this easy step you are going to need to configure it per project, which is not so easy. You will need to copy a default configuration file. This is located in /etc/awstats/ and called awstats.conf.

Copy this for each log file you wish to keep statistics of. The file names are to be like:

awstats.<project>.conf

If you’ve done this then all you need to do is change the LogFile location to the location of your apache file. And set the LogType=w to the file for indicating a website. And set the SiteDomain to the name you want AwStats to display.

Keep in mind that you should not change the location of the configuration files, since this will crash AwStats. Also make sure that the project name you choose is identical to the domain name set up in the log rotate step with -domain.

Setting up awstats on Apache

Now that the log files are being processed by AwStats it’s time to make them available through apache. To do that you will need to add the following to the VirtualHost in httpd.conf.

ScriptAlias /awstats/ /usr/lib/cgi-bin/
Alias /awstats-icon/ /usr/share/awstats/icon/
<Directory /usr/share/awstats/icon>
  Options None
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>
Now you can access the statistics by browsing to http://domain.com/awstats/awstats.pl?config=domain.

One thought on “Setting up logrotation with AWStats

  1. Pingback: Narnio » Upgrading my VPS to Debian Etch

Leave a Reply