Installing and Configuring AWStats on RHEL 6

AWStats is a free (as in beer) log analysis solution for web sites.

While Red Hat does not ship an rpm package for this software with RHEL 6, one is available from EPEL.

Installation

Use yum to install the latest awstats rpm and any dependencies.

The resulting setup will place configuration and support files under:

/etc/httpd/conf.d (an awstats.conf sets up the aliases needed to publish results)

/etc/awstats (site configuration files are here)

/usr/share/awstats (this is where most of the application files are located)

/etc/cron.hourly (an awstats script here kicks off an hourly update)

/var/lib/awstats (this is where the db files are kept, defined in each site conf file by “DirData=”).

My recommendation is that you leave these where they are until you’ve worked with the software for awhile.

Configuration

The EPEL packager has already done most of the work for you. Follow the steps below to finish the configuration.

In the examples that follow the site name is http://www.example.com and its access log is /var/log/httpd/www.example.com-access_log.

1. Make sure your set your access log type for your virtual hosts in /etc/httpd/conf/httpd.conf to “combined”, thus:


    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/html
    ServerName www.example.com
    ErrorLog logs/www.example.com-error_log
    CustomLog logs/www.example.com-access_log combined

2. Create a new site configuration file under /etc/awstats by copying the existing awstats.model.conf and naming it for your site. For example:

cd /etc/awstats
cp awstats.model.conf awstats.www.example.com.conf

3. Edit the new configuration file to set the LogFile, SiteDomain and HostAliases to your site’s real values:

LogFile="/var/log/httpd/www.example.com-access_log"
* * *
SiteDomain="www.example.com"
* * *
HostAliases="www.casalembo.com"

4. Go into /etc/httpd/conf.d/awstats.conf and add your local DNS domain (and/or any desired subnet) to allow users on your network but not on the web server itself to access awstats:

Allow from 127.0.0.1
Allow from example.com
Allow from 10.0.0.0/8

5. Shut down your web server.

service httpd stop

6. Remove all existing logs that may have been generated with the “common” log format, awstats will choke on these and refuse to commit anything.

7. Restart the web server.

service httpd start

8. Initialize the database by invoking the awstats.pl script (found under /usr/share/awstats/wwwroot/cgi-bin) with the following syntax:

perl awstats.pl -config=www.example.com -update

The script should kick back something like the following:

Create/Update database for config "/etc/awstats/awstats.www.example.com.conf"
 by AWStats version 7.0 (build 1.971)
From data in log file "/var/log/httpd/www.example.com-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: 214
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 214 new qualified records.

Testing

Test by going to the awstats url for your site. For example:

http://www.example.com/awstats/awstats.pl?config=www.example.com