AWStats on FreeBSD

AWStats Logo

AWStats PreRequisites:

Since AWStats is a web server log file analyzer, the first prerequisite is a fully functional web server.  In our case, it is Apache 2.4 on a FreeBSD 10 Server.  Additionally, the web server should have the cgi_module loaded.  Also, if geographical data is desired, then the additional port – p5-geo-ip is required.

 

Install AWStats:

# portsnap fetch update
# cd /usr/ports/www/awstats
# make install clean

 

Install p5-Geo-IP:

# cd /usr/ports/net/p5-Geo-IP
# make install clean

 

Configure Apache httpd.conf:

Uncomment the following to load the cgi module:

LoadModule cgi_module libexec/apache24/mod_cgi.so

 

Uncomment the following to use combined log file format:

CustomLog "/var/log/httpd-access.log" combined

 

Comment the following to not use the common log file format:

#CustomLog "/var/log/httpd-access.log" common

 

Add the following to the bottom of /usr/local/etc/apache24/httpd.conf:

Alias /awstatsclasses "/usr/local/www/awstats/classes/"
Alias /awstatscss "/usr/local/www/awstats/css/"
Alias /awstatsicons "/usr/local/www/awstats/icon/"
ScriptAlias /awstats/ "/usr/local/www/awstats/cgi-bin/"

     <Directory "/usr/local/www/awstats/">
         Options None
         AllowOverride None
         Require all granted
     </Directory>

     <Directory "/usr/local/www/awstats/cgi-bin/"> 
         Options ExecCGI
         SetHandler cgi-script
         </Directory>

 

Configure Apache httpd-ssl.conf:

If using SSL, ensure the CustomLog Combined Format is utilized.  Change the following line in /usr/local/etc/apache24/extra/httpd-ssl.conf file.

CustomLog "/var/log/httpd-access.log" combined
#TransferLog "/var/log/httpd-access.log"

 

Download GeoIP.dat.gz & GeoLiteCity.dat.gz:

cd /usr/local/share/GeoIP
# fetch http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
# fetch http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
# fetch http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
# gunzip GeoIP.dat.gz 
# gunzip GeoLiteCity.dat.gz
# gunzip GeoIPASNum.dat.gz

 

Configure AWStats:

Create Configuration File for web site:

# cd /usr/local/www/awstats/cgi-bin
# cp awstats.model.conf awstats.www.loga.us.conf

 

Edit awstats.www.loga.us.conf and change the following parameters:

LogFile="/var/log/httpd-access.log.1"
LogFormat=1
SiteDomain="www.loga.us"
HostAliases="192.168.0.220 localhost 127.0.0.1 REGEX[myserver\.com$]"
DirData="/usr/local/www/awstats/data"
LoadPlugin="tooltips"
LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoLiteCity.dat"
LoadPlugin="geoip_asn_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoIPASNum.dat+http://enc.com.au/itools/autnum.php?asn="

Create data directory:

# mkdir /usr/local/www/awstats/data

 

Process log files:

# /usr/local/www/awstats/cgi-bin/awstats.pl -config=www.loga.us -update

 

Create Cron Job to process log files:

# 50 9 * * * /usr/local/www/awstats/cgi-bin/awstats.pl -config=www.loga.us -update >/dev/null

 

View the Results:

http://www.loga.us/awstats/awstats.pl   —-Please substitue your own domain!

 

Log Notes:

Since the Apache Log Files are rotated using newsyslog.conf, I utilized the archived log file, httpd-access.log.1, when importing the data to AWStats.  The Log Files in /var/log are as follows:

httpd-access.log
httpd-access.log.0
httpd-access.log.1
httpd-access.log.2

Updating GeoLite Databases:

The port /net/GeoIP installed a file, geoipupdate.sh, located at /usr/local/bin/geoipupdate.sh to update the open source databases from www.maxmind.com.  The script, if executed, will update the GeoIP.dat and GeoIPv6.dat automatically without additional configuration.  In order to update the GeoLite City and the GeoLite ASN databases, you must enable them by setting GEOIP_FETCH_CITY and GEOIP_FETCH_ASN in your environment.  Read the geoipupdate.sh for details.

Here are the setting in my configuration:

GEOIP_FETCH_CITY=${GEOIP_FETCH_CITY:=True}
GEOIP_FETCH_ASN=${GEOIP_FETCH_ASN:=True}

The script can be run manually to check if the files are downloaded properly.  Once satisfied with the results, you can create a crontab entry to automate running the script on a schedule.  MaxMind updates the open source databases on the second Tuesday of each month so schedule your crontab entry to reflect this information.

 

crontab -e:

This is my crontab entry:

30     09     *      *      4      /usr/local/bin/geoipupdate.sh >/dev/null

 

Summary:

Installing and configuring AWStats was fairly easy once I familiarized myself with the configuration files and, of course, by trying different combinations until it was working as expected.  This is a compilation of that effort.

 

References:

www.awstats.org

httpd.apache.org

 

3 thoughts on “AWStats on FreeBSD”

  1. I’ve been browsing online more than three hours as of late, yet I never found
    any attention-grabbing article like yours.
    It is lovely worth enough for me. In my opinion, if all webmasters and
    bloggers made good content as you probably did, the net
    will be a lot more useful than ever before.

Leave a Reply

Your email address will not be published. Required fields are marked *