Being able to track your web statistics is important for commercial sites. For personal sites it may not be as important, but it still nice to know where people are coming from and what they are looking for.
There are a number of open source log analysers that work with Apache, however my preferred choice is Awstats.
It may not be able to give the same level of detail as a commercial package such as Urchin, but it provides more than enough detail for most purposes.
On Ubuntu you can install awstats via apt:
apt-get install awstats
This will install the base package however, if you want to lever its full power you will need to install a couple of extra Perl modules.
apt-get install libnet-ip-perl
If you would like to see which countries your visitors are based in then you should look at one of the IP to Country plugins which will give you a Geo IP lookup.
You can choose between either geoipfree or GeoIp.
Other useful plugins are:
- Plugin: HostInfo – which gives you a popup whois window
- Plugin: IPv6 – adds IPv6 support
- Plugin: Tooltips – confused by all the information? This will take away the mystery 🙂
On rpm-based system there is a handy little perl script that walks you through the initial configuration. On Ubuntu you have to do it by hand, however most of the configuration is self-explanatory.
Simply copy the provided sample config to a new config file:
cp awstats.conf awstats.yoursite.tld.conf
NB: You will need a separate configuration file for each vhost you wish to examine.
Edit the conf file to match your site’s setup. Important things to pay attention to are any domain aliases, the location of the log files and any IPs you wish to ignore (eg. your own)
You can also decide which optional plugins you want to load. Simply add a line to invoke each one:
geoipfree requires an extra perl module. On ubuntu the package is called libgeo-ipfree-perl
You are almost ready!
You now need to configure Apache to allow access to your awstats pages.
Rather than messing about with my main Apache config file I found it neater to place the awstats specific information in an external file called awstats.conf:
Allow from all
Alias /awstatsicons/ /usr/share/awstats/icon/
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Allow from all
Then use an include directive in your main Apache config (apache2.conf):
You then need to add it in to your vhost:
ScriptAlias /whereyouwanttoaccessit/ /usr/lib/cgi-bin/
If you navigate to:
You *should* be able to access your stats.
Of course you’ll need to actually generate the stats first:
/usr/lib/cgi-bin/awstats.pl -config=yourdomain.tld -update
I would recommend you run this from the command line once to create the first set of stats and then add a cronjob:
0,10,20,30,40,50 * * * * /usr/lib/cgi-bin/awstats.pl -config=yourdomain.tld -update >/dev/null
This will update your stats every 10 minutes, which means that you’ll only have to update a few lines at a time. If your site is busy this makes sense 🙂
The last part of the line is important:
By default cron emails the user each time it runs. You really don’t want 6 emails an hour telling you that Awstats has run 🙂
NB: This works for me. Your mileage may vary. If I’ve left out anything blatantly obvious please let me know