Setting up awstats to monitor site activity

Following the steps in this email thread was a good starting point,

I also drew inspiration from:

  • The DEBIAN.readme file in the /usr/share/doc/awstats folder.

This next link shows you how to setup a prerotate script under /etc/logrotate.d/apache2

Essentially this is as follows (I've modified it slightly)

1. Install awstats

  1. Install awstats and other packages for awstats plugins
    sudo apt-get install awstats libgeo-ipfree-perl libnet-xwhois-perl
  1. Copy the installed version to the location we want to run it from
    sudo cp /usr/share/doc/awstats/examples /usr/local/awstats
    sudo cd usr/local/awstats
    sudo mkdir wwwroot
    sudo mkdir wwwroot/cgi-bin
  1. Decompress and move the model config file into place so we can run the configure perl script
    sudo gunzip awstats.model.conf.gz
    sudo mv awstats.model.conf wwwroot/cgi-bin
  1. Run the configure script
    sudo ./
  1. Answer the questions for the script as follows, replacing with the domain you wish to monitor.
  1. Now make sure awstats can find everything in the correct place and modify the permissions of the access.log you wish to scrape. Use the path to the log you need.
    sudo ln -s /usr/local/awstats/css/ wwwroot/
    sudo ln -s /usr/share/awstats/* wwwroot/
    sudo ln -s /usr/lib/cgi-bin/ wwwroot/cgi-bin/
    sudo chown -R --dereference www-data:www-data wwwroot
    sudo chown -R --dereference www-data:www-data /var/lib/awstats
    sudo chown root:www-data /path/to/apache2/access.log
  1. Change the Options directive in the <Directory "/usr/local/awstats/wwwroot"> directive in /etc/apache2/httpd.conf from None to FollowSymLinks so it now reads as,
    <Directory "/usr/local/awstats/wwwroot">
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
  1. Restart apache
    sudo /etc/init.d/apache2 restart
  1. Now browse to awstats
    You should see an error message that tells you awstats is not setup properly (or similar). That's ok. We are only making sure that the script runs.

2. Configure awstats

  1. Now edit your /etc/awstats/ file:
      sudo vim /etc/awstats/
    Ensuring that the values shown are correct:
      LogType "W"
      LogFormat "1"
      HostAliases=" localhost"
    Enable the GeoIPfree plugin

3. Configure cron and logrotate

  1. Add the following entry to /etc/cron.d/awstats
    3,33 * * * * www-data [ -x /usr/lib/cgi-bin/ -a -f /etc/awstats/ -a -r /path/to/access.log ] && /usr/lib/cgi-bin/ -update >/dev/null
  1. Add the following to /etc/logrotate.d/apache2
    /path/to/*.log {
            rotate 52
            create 644 root adm
            /usr/lib/cgi-bin/ -update
                    if [ -f /var/run/ ]; then
                            /etc/init.d/apache2 restart > /dev/null
    The create 644 root adm allows read access to the logs.

4. Update the stats for the website

  1. Run to update the stats for your domain
    sudo /usr/lib/cgi-bin/ -update
    You should see something like this:
    Update for config "/etc/awstats/"
    With data in log file "/path/to/access.log"...
    Phase 1 : First bypass old records, searching new record...
    Searching new records from beginning of log file...
    Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
    Jumped lines in file: 0
    Parsed lines in file: 60
    Found 0 dropped records,
    Found 0 corrupted records,
    Found 0 old records,
    Found 60 new qualified records.

5. Browse to to view the stats

Your done.


Depending on your apache setup you may need to cut the contents of 'httpd.conf' and place the entries into (say) the appropriate VirtualHost directive. Perhaps you may need to place awstats into its own VirtualHost directive as, say, you want to access this sort of information under a separate sub-domain.