Awstats

I had installed a web traffic analyser a long time ago but forgot about it until recently. As usual I used my site as my test / learning sandbox and it was fairly easy to install form what I remembered. Of course I used a Ubuntu server for all of this and thereforeall the paths mentioned are Ubuntu specific.

Overview

Awstats analyses access logs generated by web servers. It supports Apache and works best with combined logs. Awstats can be used for Microsoft’s IIS but have read that it’s not as compatitble as Apache. I will be using Apache as my example.

Installing AWstats

Again using the “apt-get” method it was very easy to install. On Gutsy 7.10 it has the older version but it will do.
sudo apt-get install awstats
Once install all the icons and web related files are located in:
/usr/share/awstats/
You’ll need this later on. The program configuration files can be found in:
/etc/awstats
First off download the GeoIP database which Awstats will use as a lookup table for IP and countries. I put my GeoIP.dat file in:
/usr/local/share/GeoIP
create the directory:
sudo mkdir /usr/share/GeoIP/
navigate to the directory that was just created:
cd /usr/share/GeoIP/
download the binary database from Maxmind
wget http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
Unzip the database:
sudo gunzip GeoIP.dat
The result should be a GeoIP.dat file:
ls

Configuration

Go to the Awstats config file directory:
cd /etc/awstats
For every virtual host / web site you want to get stats for you must create a configuration for. Once one is setup, multiple copies of the configuartion can be made and just change the domain name and the access log location. I will use “mysite.com” as my domain.

First make a copy of the original config file just in case something goes wrong:
sudo cp awstats.config awstats.config.bak
Create another copy for the website. I will use Peter’s naming convention: Remember to replace mysite.com with the real domain name.
sudo cp awstats.conf awstats.mysite.conf
Edit the new configuration file and change all the values below:
vim awstats.mysite.conf

LogFile=”/var/log/apache2/access.log” [Change to the location of the access.log file for the website]
LogType=W [Its a web log that it will be analysing]
LogFormat=1 [Apache log format]
LogSeperator=” ”
SiteDomain=”mysite.com” [domain name to be analysed. Used to identify which site when used to generate]
HostAliases=”mysite.com, localhost” [List all the domain names used to access your site]
DNSLookup=1
LoadPlugin=”geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat” [Location of the GeoIP database]

Once all the awstat config files are done you must edit the Apache config so Apache knows what to do .
cd /etc/apache2/sites-available
For every Awstats enabled site the following entry must be put in the virtual host. I’m sure there is a way to write this directive once and all sites should be configured properly but I have yet found a way to do this. The that needs to be added between
Alias /awstats-icon/ /usr/share/awstats/icon/
Reload Apache to make the changes take affect:
sudo /etc/init.d/apache2 reload
Awstats must generate the stats with the following command:
/usr/lib/cgi-bin/awstats.pl -config=mysite -update
Change mysite.com to the “SiteDomain” that was in the awstats.mysite.conf file.
Once this has been done the stats will be available to view online at:
http://mysite.com/cgi-bin/awstats.pl?config=mysite.com

Schedule Awstat Updates

It will be annoying if the update command must be typed every time for Awstats to update the stats. Using crontab it can be scheduled to update the stats. For every awstats.mysite.config file you must create a seperate entry in crontab. This can be doing the following:
crontab -e
Open crontab in edit mode.
0 1 * * * /usr/lib/cgi-bin/awstats.pl -config=mysite -update
The above command will update Awstats every day.

Resouces

Daniel’s NFC Development Weblog
Peter’s Blog

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *.

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.