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

or (in case you have more than one config file)

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

 

Feedback

thank you this is very good tutorial
Psychic Zero
October 29, 2009
#1
Installation explained in a truly simple manner.
Ajay
January 18, 2010
#2
Simple but excellent
luts
February 8, 2010
#3
Quick Question.. I just installed it, and i was wonderign if its possible to make the URL private.. I dont want the whole world to see my access reports..
Thanks
Maxime
February 18, 2010
#4
Spot on. There are a lot of really over complex guides out there, this gets the job done flawlessly.

Thanks.
Rich
May 17, 2010
#5
Thanks. Worked a treat.
Doc John
May 23, 2010
#6
Thank you very much!
Kevin
July 12, 2010
#7