We are going to use AWstats for gathering and displaying request statisticts from the Apache<. SAWstats<, an improved version of AWstats, can be used to analyze Nginx< and Squid< access logs.

This installation guide for CentOS 5 is based on AWstats documentation< and guide from lissyara<.

AWstats installation

Start from installing the attached awstats tarball or awstats-xxx.noarch.rpm<.

mkdir /etc/awstats
cp /usr/etc/awstats/awstats.model.conf /etc/awstats/awstats.conf<

Edit awstats.conf:

HostAliases=" REGEX[.*\.ourdom\.com] localhost"

Note about log formats:

%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"
"%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
(host user date method url code size referer ua)
date time c-ip cs-username cs-method cs-uri-stem sc-status sc-bytes cs-version cs(User-Agent) cs(Referer)
(date host user method url code size ua referer)
date method code host ua referer url size
%h %l %u %t \"%r\" %>s %b
(host user date method url code size) 

Format for Apache with virtual host name at the end:

 %host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot %virtualname<

Format for Nginx with virtual host name at the end:

 %host %other %logname %time1 %method %url %other %codequot %bytesd %refererquot %uaquot %otherquot %virtualname <

Verify that standard perl modules exist

perl -MURI::Escape -e1
perl -MStorable -e1<

Create work directory

mkdir /var/lib/awstats<

Enable hostinfo - install perl whois module

cpan Net::XWhois<

and add the following in awstats.conf


Create cron job in /etc/cron.hourly/awstats

/usr/local/awstats/wwwroot/cgi-bin/ -update<

Augment Apache configuration

# Directives to allow use of AWStats as a CGI
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"

# This is to permit URL access to scripts/files in AWStats directory.
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all

Install GeoIP C API

yum install GeoIP GeoIP-data GeoIP-devel<

Install GeoIP perl module (the devel package is required for build)

cpan Geo::IP<

Create directory for GeoIP data

mkdir -p /var/www/geoip/data<

Download geolite country< and geolite city< binary files GeoIP.dat.gz< and GeoLiteCity.dat.gz< from free maxmind database< or full latest version<.

Move downloaded files to /var/www/geoip/data. Enable GeoIP in /etc/awstats.conf

LoadPlugin="geoip GEOIP_STANDARD /var/www/geoip/data/GeoIP.dat
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/www/geoip/data/GeoIPCity.dat"<

Recreate statistics

rm /var/lib/awstats/*
sh /etc/cron.hourly/awstats<

Restart apache and surf to this url<


JAWstats< is addon to AWstats on javascript steroids (see demo<). Download the latest version< (I checked out the latest version from SVN< because I needed "statsname" setting) and unpack into /var/www/admin/jawstats. Copy config.dist.php into config.php and adjust a few parameters:

$aConfig[""] = array(
  "statspath"   => "/var/lib/awstats/",
  "statsname"   => "awstats[MM][YYYY].txt",
  "updatepath"  => "/awstats/",
  "siteurl"     => "",
  "sitename"    => "Our Dom Ltd",
  "theme"       => "default",
  "fadespeed"   => 250,
  "password"    => "my-1st-password",
  "includes"    => "",
  "language"    => "en-gb"