Install Awstats on Ubuntu

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
Oct 29, 2009
#1
Installation explained in a truly simple manner.
Ajay
Jan 18, 2010
#2
Simple but excellent
luts
Feb 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
Feb 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
Jul 12, 2010
#7
Jérôme, this was easily the most helpful, concise, and informative description on setting up AWStats that I have seen after scouring Google for a good amount of time.

Thanks for the post!
Matt Layman
Sep 11, 2010
#8
nice job! That was so easy! Usingit with jawstats now. Looks really nice
Michael
Dec 11, 2010
#9
Thanks! Nice tutorial
KevinK
Apr 6, 2011
#10
Hey, thanks for the tutorial: One error I found is that you don't need the "root" part at the beginning of the crontab command line. this produces an error. you just need to install the crontab for user root, so the correct line should be:

*/15 * * * * /usr/lib/cgi-bin/awstats.pl -config=www-surfer.com -update > /dev/null

to run it every 15 min.
Fabian Koehler
May 30, 2011
#11
Ok, sorry, this was my fault. Of couse you are editing /etc/crontab directly. so the "root" user in the beginning makes sense :)
Fabian Koehler
May 30, 2011
#12
Hey, I like the large font. Even I can see it this way. It is a nice tutorial and easy to follow, unlike many others where you have to figure out what you actually just saw.
Norbert, KJ6ZD
May 31, 2011
#13
Just awesome, thanks! I wish there were more tutorials available like this for Ubuntu.
Tom Purl
Jul 11, 2011
#14
Thanks, really accurate article
Meh
Jul 28, 2011
#15
Nice..
sofasurfer.ch
Aug 23, 2011
#16
Excellent tutorial, had awstats up and running within minutes.
seanp
Aug 29, 2011
#17
Thanks a lot.

Is there a way, I can link it to a login
PRABHAT
Sep 28, 2011
#18
sudo -i

Don't like to write sudo all the time
Anders
Oct 26, 2011
#19
EXCELLENT TUTORIAL!!!
Patrick Kelley
Feb 14, 2012
#20
Thanks a lot. You helped me setting up AWStats.
TK
May 29, 2012
#21
Oii eu estalar um jogos
welton lima
Jan 11, 2013
#22
nice totu tkx
fekih.romdhane.amine@gmail.com
Feb 4, 2013
#23
I can confirm it still works on Ubuntu 12.10.

Warning! If you monitor a public server, then the statistics are public either: BIG security hazard!
ike
Apr 25, 2013
#24
thanks for these straightforward explications! works as is on ubuntu 13.04.
Yaurthek
Aug 17, 2013
#25
Thanks for this very clear tutorial !
Works like a charm on latest Debian.
Guihome
Aug 18, 2013
#26
muy bueno
MatiasFernandez
Oct 18, 2013
#27
Thank you so much!
Alex P.
Jan 11, 2014
#28