Mar 17

Getting started with awstats

Category: Linux   — Published by tengo on March 17, 2008 at 7:22 am

A short how-to for awstats. Lately, when I found out analog falls short in terms of geo IP functionality, I decided to switch to awstats.

Running debian and a webserver, I downloaded the awstats archive and extracted it on a reachable path within the www root of my server. Next I customized the shipped awstats config file which can be found in the /wwwroot/cgi-bin subdirectory.

In order to get things to work right out of the box, make awstats.pl readable and executable by the webserver, then edit awstats.model.conf to suit your needs:

  • Edit the location of your logfile
  • Tell awstats the name of your domain (www.yourdomain.com)
  • Decide (which I did) which plugins to activate

Finally save it as awstats.www.yourdomain.com.conf (see how the value IN the config file relates to the fileNAME of the conf file?)

The next stept is to try to access awstats from the web. Type http://www.yourserver.com/path/to/awstats/cgi-bin/awstats.pl The script should print out a basic frame of what a report looks like without any data. This is because awstats is made up of two procedures. A analyzation pass and a visualisation pass. When invoked from the web via cgi, awstats is in visualization mode and just presents formerly computed data. As we did not do an analyzation pass before, the framework is empty.

Ok, next we do the computation. Log into your server via SSH and dig down to the awstats.pl script. Type

perl awstats.pl -config=www.yourdomain.com -update

If you decided to use geoip information to resoilve numeric IP addresses back to useful information, you have to do the following first:

1. Install the GeoIP C libraries.

apt-get install libgeoip1 geoip-dev (Debian 4.0)
apt-get install libgeoip1 libgeoip-dev (Debian 6.0 Squeeze)

2. Install the associated GeoIP tables data.
You can get it for free from MaxMind

wget http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz

wget http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

ungzip them with

gzip -d GeoIP.dat.gz && gzip -d GeoLiteCity.dat.gz

and move these data files to a location you like, i.e. within your /home/path
The default dir is /usr/share/GeoIP/GeoIP.dat but it might be handy to have symlinks in /usr/local/share/GeoIP/GeoIP.dat.

3. Install the required perl tools to use the data.

You can find the Geo::IP module at cpan

When I tried to use the version 1.30 odf this module I got into some trouble. My compiler kept spitting out

Makefile.PL INSTALLDIRS=site' returned status 512, won't make
IP.xs: In function 'XS_Geo__IP__Record_city': error: structure has no member named `charset'

I finally found it that this is a problem with the latest release of the module. The solution is to use the older revision 1.27. Install it with cpan with

$ cpan -i TJMATHER/Geo-IP-1.27.tar.gz

or via command line with

$ wget http://search.cpan.org/CPAN/authors/id/T/TJ/TJMATHER/Geo-IP-1.27.tar.gz
$ tar xvf Geo-IP-1.27.tar.gz

$ cd Geo-IP-1.27.tar.
$ perl Makefile.PL
$ make
$ make test
$ make install

Then enable the GeoIP plugins in the awstats.www.yourdomain.conf file and be sure to supply the path/to/your/geoip-data

Read on: