Jump to: navigation, search


Time has come to create some statistics for your web sites. Webalizer is commonly used for this but development on Webalizer stopped several years ago and it lacks updates to recognize recent browsers and other vital things. This guide will use AWStats instead.


Install it form ports as usual. Just leave the default values on the options page.

# cd /usr/ports/www/awstats
# make
# make install clean

You will also need GeoIP.

# cd /usr/ports/net/p5-GeoIP-PurePerl
# make
# make install clean
# mkdir /usr/local/share/GeoIP
# cd /usr/local/share/GeoIP
# wget
# gunzip GeoIP.dat.gz

AWStats will install itself in /usr/local/www/awstats which is inside the default path of your Apache installation. The output from the installation suggests a few additions to your Apache configuration. Those additions will create a global alias to this folder meaning that any of your virtual hosts will use this copy of AWStats simply by adding /awstats to the url. No need to maintain a separate copy for each host. Open /usr/local/etc/apache22/httpd.conf in your editor and add the following lines at the bottom but before the last Include line.

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

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

Restart Apache.

# /usr/local/etc/rc.d/apache22 restart

You need a config file for each of the virtual hosts you want to gather statistics for and I will guide you through the creation of the config file for in this tutorial. AWStat's config files must be located in /usr/local/www/awstats/cgi-bin and they have to be named awstats.your.vhost.domain.conf. There's a template included so start by making a copy of it and open the copy in your editor.

# cp /usr/local/www/awstats/cgi-bin/awstats.model.conf /usr/local/www/awstats/cgi-bin/
# ee /usr/local/www/awstats/cgi-bin/

The first thing to tell AWStats is where to find the log file for this domain. In your setup you don't have a single log file, but one for each month because you configured log rotating if you followed the guide correctly. Because of this you need to merge them and AWStats include a tool to help you do that and an example is shown in the template. Find the following line:


Change it to:

LogFile="../tools/ /usr/home/myweb/public_html/*.www.log |"

This will catch every logfile belonging to regardless of the date in the filename. Don't forget the pipe sign at the end.

Find and change the following options. Don't forget to remove the comment on the GeoIP line.

SiteDomain=""                                             ->   SiteDomain=""
HostAliases="localhost REGEX[myserver\.com$]"   ->   HostAliases=""
DNSLookup=2                                               ->   DNSLookup=0
AllowFullYearView=2                                       ->   AllowFullYearView=3
LevelForWormsDetection=0                                  ->   LevelForWormsDetection=2
ShowWormsStats=0                                          ->   ShowWormsStats=HBL
ShowScreenSizeStats=0                                     ->   ShowScreenSizeStats=1
#LoadPlugin="geoip GEOIP_STANDARD /pathto/GeoIP.dat"      ->   LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"

Now you must run manually the first time to look for any errors. Note that the -config parameter only contains your domain name and not the full name of the config file.

# cd /usr/local/www/awstats/cgi-bin
# perl -update

If everything looks fine you can add the following line to crontab.

@hourly cd /usr/local/www/awstats/cgi-bin ; perl -update >/dev/null

If you have more sites to run statistics for, you'll just create another config file and add that update command to the end of the crontab entry above so they won't all run simultaneously. To watch the statistics, simply browse to the script and AWStats will automatically chose the correct config file by checking the url requested -


Personal tools