Friday, April 02, 2010

AWSTATS on ubuntu

Install Awstats on Ubuntu

This has been tested with Ubuntu server 8.04 (Hardy Heron).

Installation

sudo aptitude install awstats
To see the country of your visitors (not required)

sudo aptitude install libnet-ip-perl
sudo aptitude install libgeo-ipfree-perl
Configuration

Let's assume you want to analyze the Apache 2 log file of your website “toto.com” (It can be just an IP address).

Create configuration file

sudo cp /etc/awstats/awstats.conf /etc/awstats/awstats.toto.com.conf
Update these parameters

# apache2
LogFile="/var/log/apache2/access.log"

# domain name
SiteDomain="toto.com"
HostAliases="localhost 127.0.0.1 toto.com"

LogFormat=1
You can also activate these plugins

LoadPlugin="tooltips
LoadPlugin="geoipfree"
Run

sudo /usr/lib/cgi-bin/awstats.pl -config=toto.com -update
You should get something like this

Create/Update database for config "/etc/awstats/awstats.toto.com.conf" by AWStats version 6.7 (build 1.892)
From data in log file "/var/log/apache2/access.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 191338
Found 0 dropped records,
Found 24 corrupted records,
Found 0 old records,
Found 191314 new qualified records.
Configure Apache to view the statistics

Create /etc/apache2/conf.d/statistics

Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon/ "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /statistics/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Restart Apache

sudo /etc/init.d/apache2 restart
View your statistics

http://toto.com/statistics/awstats.pl
or (in case you have more than one config file)

http://toto.com/statistics/awstats.pl?config=toto.com
Update your statistics with cron

In /etc/crontab add

# update every 10 min
*/10 * * * * root /usr/lib/cgi-bin/awstats.pl -config=toto.com -update > /dev/null
How to reset awstats

Just delete the files in /var/lib/awtstats (directory defined by DirData parameter)

sudo su - root
cd /var/lib/awstats
rm *
logout
Notes

you have to be root because for some reason, sudo rm -R awstats/* wouldn't work.
if you get the message Never updated (See 'Build/Update' on awstats_setup.html page) whereas the awstats files are there in /var/lib/awtstats, it's probably a permission problem on this folder.
Source: http://awstats.sourceforge.net/docs/awstats_faq.html#RESET

Troubleshooting

awstats "Error: SiteDomain parameter not defined in your config/domain file. You must edit it for using this version of AWStats. "
Try to this URL (with your values): http://toto.com/statistics/awstats.pl?config=toto.com

Reference

http://ubuntu-tutorials.com/2008/01/16/configuring-awstats-on-ubuntu-server/
http://www.mneylon.com/blog/archives/2005/08/03/configuring-awstats-with-apache-2-on-ubuntu/
http://awstats.sourceforge.net/
http://awstats.sourceforge.net/docs/awstats_faq.html

No comments: