Install AWStats with GeoIP Plugin


Hits: 7420  

AWStats is a free analytic tool that generates web, streaming, ftp or mail server statistics, graphically. There are many log analyzer but AWStats is open source Web analytics reporting tool, It can analyze log files from Apache, WebStar, IIS.

Installing AWStats on ubuntu 12.04

# apt-get install awstats

Configuring for yourdomain.com replace yourdomain.com with your real domain

# cp /etc/awstats/awstats.conf /etc/awstats/awstats.yourdomain.com.conf
# vi /etc/awstats/awstats.yourdomain.com.conf

Check you have below settings in /etc/awstats/awstats.yourdomain.com.conf

LogFile=”/var/log/apache2/access.log”
SiteDomain=”yourdomain.com”
HostAliases=”localhost 127.0.0.1 yourdomain.com”
DNSLookup=1
LogFormat=1
AllowFullYearView=3

Generate stats for AWStats for /var/log/apache2/access.log file (Make sure you have fresh log file)

# /usr/lib/cgi-bin/awstats.pl -config=yourdomain.com -update

configuration Apache2 with password

# htpasswd -c /etc/awstats/awstats.pwd admin
# chmod 755 /etc/awstats/awstats.pwd

# vi /etc/apache2/sites-available/awstats

<VirtualHost *:80>
ServerName awstats.yourdomain.com
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error_awstats.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access_awstats.log combined
<Directory “/usr/lib/cgi-bin/”>
<Files “awstats.pl”>
Options +ExecCGI
</Files>
</Directory>
Alias /awstats-icon/ “/usr/share/awstats/icon/”
<Directory /usr/share/awstats/icon>
Options None
AllowOverride All
Order allow,deny
Allow from all
</Directory>
RewriteEngine on
RewriteRule /awstats-icon – [L]
RewriteCond %{QUERY_STRING} !^(.*&)?framename=index(&.*)?$
RewriteCond %{QUERY_STRING} ^(.*&)?framename=.*(&.*)?$
RewriteRule /(.*) /usr/lib/cgi-bin/awstats.pl [L]
RewriteCond %{QUERY_STRING} ^(.*&)?config=([^&]*)(&(.*))?$
RewriteRule /.* /%2?%1%4 [R,L]
RewriteRule /awstats.pl$ / [R,L]
RewriteRule /([^/]*)(/.*)? /usr/lib/cgi-bin/awstats.pl?config=$1 [QSA,L]
<Location />
SetHandler cgi-script
Satisfy any
Order deny,allow
Deny from all
AuthType Basic
AuthName “AWStats Access”
AuthUserFile /etc/awstats/awstats.pwd
require valid-user
</Location>
<LocationMatch /(?!awstats.pl|robots.txt)$>
Require user admin
</LocationMatch>
<Location /awstats-icon>
SetHandler None
Allow from all
</Location>
</VirtualHost>

Enable Virtual Host

# a2ensite awstats
# apache2ctl configtest
# /etc/init.d/apache2 reload

Auto update stats

# crontab -e

*/10 * * * * /usr/share/awstats/tools/update.sh
10 03 * * * /usr/share/awstats/tools/buildstatic.sh
*/10 * * * * /usr/lib/cgi-bin/awstats.pl -config=yourdomain.com -update > /dev/null

Set proper permission on logs

# sudo chmod 644 -R /var/log/apache2/*
# chmod 644 /var/log/apache2

# vi /etc/logrotate.d/apache2   (Replace create 640 root adm with create 644 root adm)

Install GeoIP for AWStats

# apt-get install build-essential zlib1g-dev apg libgeo-ipfree-perl libnet-ip-perl libnet-dns-perl liburi-perl apache2-utils

# cd /usr/src/
# wget http://zlib.net/zlib-1.2.8.tar.gz
# tar xvzf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure –prefix=/usr/local/zlib && make && make install

# wget http://www.maxmind.com/download/geoip/api/c/GeoIP-latest.tar.gz
# tar xzvf GeoIP-latest.tar.gz
# cd GeoIP-1.6.0
# ./configure && make && make install

# cpan
> install YAML
> install Geo::IP Geo::IPfree Geo::IP::PurePerl URI::Escape Net::IP Net::DNS Net::XWhois Time::HiRes Time::Local
> quit

# cd /usr/src/
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
# gzip -d GeoLiteCity.dat.gz
# cp GeoLiteCity.dat /usr/share/GeoIP/GeoLiteCity.dat

Enable AWSTAT configuation for LoadPlugin

# vi /etc/awstats/awstats.yourdomain.com.conf

Remove comment from /etc/awstats/awstats.yourdomain.com.conf

LoadPlugin=”geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD /usr/share/GeoIP/GeoLiteCity.dat”

# /etc/init.d/apache2 reload

AWStats will run here

http://awstats.yourdomain.com/yourdomain.com

AWStats-Stats

AWStats-country

AWStats-hours

Error opening /usr/share/GeoIP/GeoIPCity.dat at /usr/local/share/perl/5.14.2/Geo/IP/PurePerl.pm line [file name in /usr/share/GeoIP]

Make sure you have all files in folder /usr/share/GeoIP/GeoLiteCity.dat else copy

# cp /usr/share/GeoIP/GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat

AWStats-UA

Other log file analysis and reporting tools

http://sawmill.net/
http://goaccess.io/
http://www.apacheviewer.com/
http://www.loganalyzer.net/
http://www.webalizer.org/
http://piwik.org/log-analytics/
http://www.w3perl.com/
http://http-analyze.org/index.php