Awstats i think has lost the lime light in the last few years thanks to Google Analytics, but that dosent mean its useless. Its quick and unlike Google Analytics the latest stats are not a few days old, well they arent if your cron jobs run on regular basis anyhow. This post aims to show you how to get awstats up and running on your Ubuntu based server, with the stats of a virtual host pulled straight from the Apache log files.
First login in to your server via SSH and become root:
sudo su
Update your package list:
apt-get update
Install the awstats program:
apt-get install awstats
Create a new configuration file for the virtual host you would like to gather statistics on:
cp /etc/awstats/awstats.conf /etc/awstats/awstats.mydomain.tld.conf
You will need to create a separate configuration file for each virtual host you would like to gather statistics about. Of course when the virtual host is setup in Apache it will need its own log files.
To see where our visitors hail from we will also need to install a PERL GeoIP library:
apt-get install libnet-ip-perl libgeo-ipfree-perl
Now its actually time to edit the awstats file for you virtual host so it contains the appropriate settings, lines you may need to look at are:
Line 51 - This needs to point to the access log of the virtual host
Line 122 - Make sure the log type reflects the format Apache is writing
Line 153 - Change this to the domain name of your site
Line 168 - Aliases etc that can be used to access the virtual host
Line 329 - To protect access to the sites statistics
Line 340 - “” “” “” “” “”
Line 350 - “” “” “” “” “”
Line 362 - Should Awstats create a directory for storing reports if it dosent already exist
Line 372 - Should Awstats use a text or XML file to build the stats database
Line 382- XHTML or HTML statistic reports
Line 413 - Should Awstats empty the access log after a parsing it can save having to worry about rolling it.
Line 428 - Tells Awstats if you would like to archive the logs which it has already parsed
Line 450 - The default name of the report file
Line 466 - Clients that should be skipped in the reports i.e your own IP address
Line 479 - Skip certain user agents i.e wget etc
Line 497 - Dont count certain files on your site
Line 732 - Turn on Awstats debugging for more verbose output
Line 1255 - If you want to enable extra toolips in your reports
Line 1271 - Reverse lookups for IPV6 IP address’s
Line 1302 - Use of a free GeoIP service for country to IP lookups
After the configuration is finished for our virtual host you will need to configure Apache so you can access your statistics.
Create a new file for Apache with:
pico /etc/apache2/conf.d/awstats
In this file put the content:
Alias /awstatsclasses “/usr/share/awstats/lib/”
Alias /awstats-icon/ “/usr/share/awstats/icon/”
Alias /awstatscss “/usr/share/doc/awstats/examples/css”
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Now restart the Apache service so you changes to the configuration take effect:
/etc/init.d/apache2 restart
Now add a line to your crontab to update your statistics every so often:
pico /etc/crontab
And add the following line to update your stats every 20 minutes:
*/20 * * * * root /usr/lib/cgi-bin/awstats.pl -config=mydomain.tld -update >/dev/null
Save the changes and just to be on the safe side try and update the stats drom the command line with:
/usr/lib/cgi-bin/awstats.pl -config=mydomain.tld -update
Note: If you get an error that looks like
Error: SiteDomain parameter not defined in your config/domain file. You must edit it for using this version of AWStats.
Setup (‘/etc/awstats/awstats.conf‘ file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in ‘docs’ directory).
Just delete the /etc/awstats/awstats.conf file and it will read the one you are trying to specify instead.
Now to see the statistics for the site you just generated type the hostname of your server into a browser followed by /awstats/awstats.pl?config=mydomain.tld i.e
http://www.myserver.com/awstats/awstats.pl?config=mycooldomain.com
With any luck you should now have access to a webpage with some pretty detailed statistics on your domain.