Installing AWstats

Today I decided to install AWStats for analysing my webserver traffic.

Running Debian Etch with apache 2.2 on the webserver / webproxy, the following steps are taken:

  • Install awstats with apt-get install awstats
  • Put following in /etc/awstats/awstats.conf.local:

  • Install the needed perl libs:
    apt-get install libnet-dns-perl libnet-ip-perl libnet-ipv6addr-perl liburi-perl
  • Create config files for each website running:
    vim /etc/awstats/

    Include "/etc/awstats/awstats.conf"
    DefaultFile=”index.php index.html”

    The log format is set to 1. This is the apache combined log format, with referer URLs and browser info. Use 4 for the simple apache log format (however I would recommend combined format anyway)

  • After this, some weird bug showed up in awstats. It warns about nested includes that don’t work because perl version < 5.6 is installed. Great, I got 5.8.8. I found this bug on and applied the patch.
  • Next thing to do is to create initial awstat databases with the logfiles I already have.
    One problem: they are alreay rotated several times. This can be solved this way:
    rm /tmp/logfile

    for i in `ls* | sort -n -r -t . -k 5`; do
    zcat $i >> /tmp/logfile;

    cat >> /tmp/logfile
    cat >> /tmp/logfile

    Edit /etc/awstats/ to temporarily use /tmp/logfile instead of /var/log/apache2/

    perl /usr/lib/cgi-bin/ -update

    And edit back /etc/awstats/ with the usual logfile.

  • Great. all old stuf is in awstats database! Now make it visible:

    cp /usr/share/doc/awstats/examples/apache.conf /etc/apache2/awstats.conf

    Include this file in your favorite virtual host container where awstats stuff can be viewed by authorized people only. Higly recommended, the reputation of CGI makes it neccessary to do so.
    After inclusion, the script alias ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ could be removed because it was already mentioned in my virtual host.
    Now, when calling , you should be able to see all gathered data in the log files.
  • Now we want the awstats dbases update automagicly every 10 minutes, and just before rotating the apache logfiles:
    EDITOR=vim crontab -e

    # m h dom mon dow command
    */10 * * * * for config in `ls /etc/awstats/awstats.*.conf | cut -f2,3,4 -d"."`; do perl /usr/lib/cgi-bin/ -config=$config -update; done

    vim /etc/logrotate.d/apache2
    and add:

    for config in `ls /etc/awstats/awstats.*.conf | cut -f2,3,4 -d"."`; do
    perl /usr/lib/cgi-bin/ -config=$config -update

    in the /var/log/apache2/*.log block.

Done! My statistics get updated once per 10 minutes and I can view them easily via the CGI with the paramater ?

Leave a Reply