AWStats: Graphical View of Your Logs

by Mike on April 17, 2009 · 5 comments

in Web Server

Install  AWStats on CentOS 5.3                                                                                     Written by Adam Adamou

From AWstats website:  “AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages. It uses a partial information file to be able to process large log files, often and quickly. It can analyze log files from all major server tools like Apache log files (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS (W3C log format) and a lot of other web, proxy, wap, streaming servers, mail servers and some ftp servers.”

The installation procedure is done on a typical LAMP install on CentOS 5.3 x64_86
Your apache needs the combined log directive for the virtual host you are going to monitor with AWStats, so in your virtualhost you must have something like:
CustomLog logs/ combined
If you use the common log format some statistic features (browsers, os, keywords…) can’t work.

In this tutorial I am using so change it with your own domain and docroot location.

As root install the rpmforge repository:

# wget
# rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

# yum install yum-priorities   # if you have other repos you might want to add the priority options in the .repo file so you don’t mess up packages. More info

In case you are using i386 change the .x86_64 with .i386

# yum install awstats

Optional: (To see what countries are visiting your website)

# yum install perl-Geo-IP
# yum install GeoIP-data

Prepare the configuration file:

# cd /etc/awstats
# mv awstats.model.conf awstats.model.bak # Keep a backup of the original
# mv awstats.localhost.localdomain.conf # Change it to your domain

Edit the configuration file:

# vi /etc/awstats/

In line 51: change LogFile=”/var/log/httpd/access_log” to the location of the access_log file you want to gather statistics.

Ex: LogFile=”/var/log/httpd/”

In line 153: change  SiteDomain=”localhost.localdomain” to SiteDomain=””

In line 168: change HostAliases=”localhost″ to  HostAliases=””

In line 203: change DirData=”/var/www/awstats” to your docroot.
Ex: DirData=”/var/www/htdocs/”

If you installed the Geo-IP plugins you need to enable it:

In line 1305 change #LoadPlugin=”geoip GEOIP_STANDARD /pathto/GeoIP.dat” to LoadPlugin=”geoip GEOIP_STANDARD /var/lib/GeoIP/GeoIP.dat”

Move the awstats directory to your docroot:

# mv /var/www/awstats /var/www/htdocs/

Change the permissions to the awstats directory:

# chown -R  localuser:apache /var/www/htdocs/

Edit the awstats.conf to setup the aliases and restrictions:

# vi /etc/httpd/conf.d/awstats.conf

Change the Alias, ScriptAlias and Directory location to where the awstats is in your docroot.


Alias /awstats/icon/ /var/www/htdocs/

ScriptAlias /awstats/ /var/www/htdocs/
<Directory /var/www/htdocs/>
Options ExecCGI
order deny,allow
deny from all
allow from 192.168.1.  # Allow access to awstate from the subnet only

#Alias /css/ /var/www/awstats/css/
#Alias /js/ /var/www/awstats/js/

Reload Apache:

# service httpd reload

In case you don’t have the Options FollowSymLinks in httpd.conf, awstats will not work so you need to add it in the /etc/httpd/conf.d/awstats.conf above.
Options ExecCGI
Options FollowSymLinks

Update your statistics:

# cd /var/www/htdocs/

# perl -update

If you see something like:

Create/Update database for config “/etc/awstats/” by AWStats version 6.9 (build 1.925)
From data in log file “/var/log/httpd/”…
Phase 1 : First bypass old records, searching new record…
Direct access after last parsed record (after line 4)
Jumped lines in file: 4
Found 4 already parsed records.
Parsed lines in file: 13
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 13 new qualified records.

Then everything went fine.

If you changed your logs from common to combined it might throw some errors when you update awstats so you need to clean the log file to have only the combined logs:

# cat /dev/null > /var/log/httpd/

run the update again:

# perl -update

Navigate to

If the update time on the upper left hand corner is the same as the time you run the update and you can see the statistics, then everything works fine.

Setup the cron job (it will run hourly and redirect the output to /dev/null so it’s not going to send an email to root every hour) :

cd /etc/cron.hourly
echo “perl /var/www/htdocs/ -update > /dev/null 2>&1″ >
chmod 755

test the script:

Refresh your browser and if the update time changes then you are all set.

Enjoy the statistics on your website!


oes tsetnoc October 1, 2009 at 8:06 pm

Great code, works like a charm, however now with the thumbnails, my right hand sidebar becomes unaligned and goes to the center, beneath the archives…

cumquott October 30, 2009 at 8:08 am

Nice. Not “plug & play”, exactly, for my web server setup, but pretty close. The fact that all the steps are so clearly listed helped immensely. Most of the differences are path-related and not a big issue.

Thanks for your time to write this up.

Fabiano November 19, 2009 at 1:32 pm

Excellent post! Thank you very much for taking the time to put this tutorial together. It helped me immensely to understand how to set up AWStats and I am sure it will help a lot of people.

Aieie Brazo May 10, 2010 at 1:25 pm

Great and clear guide. Thanks.

Yugi July 6, 2010 at 8:16 am

This post is very clear and can able to configure in single shot.

Thanks for the post, it helps me with out wasting time on awstats

Previous post:

Next post: