Configure Awstats for Apache


Awstats is a free log analyzer written in Perl. It allows to build cute report graphs according to the visit’s stats. It is using the data from the access logs.

I’ll describe the configuration approach using Linux Ubuntu. The approach doesn’t differ much for CentOS.

Let’s install the required software:

apt-get install awstats libapache2-mod-perl2

The Awstats will be installed into the following folder:

/usr/share/awstats

Configuration files will be located in the following folder:

/etc/awstats

The parser script will be located in the following folder:

/usr/lib/cgi-bin/

Next we need to create the configuration file for the website:

cp /etc/awstats/awstats.conf /etc/awstats/awstats.my_cool_site.com.conf

It is recommended to use separate files if you have multiple websites running on the server.

Next lets edit the configuration file.

nano /etc/awstats/awstats.my_cool_site.com.conf

Find and update the following configuration variables:

LogFile=”/var/log/apache2/site_access.log” #path to logfile;
LogFormat=1 #for full statistics;
SiteDomain=”my_cool_site.com” #domainname;
HostAliases=”www.my_cool_site.com my_cool_site.org” #site aliases

Next we need to configure Apache to work with awstats.

First of all make sure that mod_perl is loaded:

apache2ctl -M |grep perl

or

apachectl -t -D DUMP_MODULES |grep perl

Next we need to create the apache configuration files for awstats or make sure that the file exists and contains the required data:

nano /etc/apache2/conf.d/awstats.conf

or

nano /etc/httpd/conf.d/awstats.conf

The following data is important in it:

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 /awstats/ /usr/lib/cgi-bin/
<Directory “/usr/lib/cgi-bin/”>
    Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
</Directory>

Next we need to create the cronjod that will run the log parser:
*/20 * * * * /usr/lib/cgi-bin/awstats.pl -config=my_cool_site.com -update > /dev/null

The log file will be processed every 20 minutes. You can either increase or reduce the time interval. With the bigger intervals awstats requires more time and system resources to parse the log and build graphs.

Awstats has its own data storage where it locates the information about parsed logs. Every time the parser will start to process the log file from the point where it stopped last time.

The stats page will be available on the following URL:
http://my_cool_site.com/awstats/awstats.pl?config=my_cool_site.com

It is highly recommended to protect the stats page with the basic authentication popup. This can be done with .htaccess.

Share Button

Leave a Reply

You must be logged in to post a comment.