After brewing a great Latin America coffee from Peru I received an email from on of my clients. The client recently installed Apache on RedHat RHEL and wanted to install and configure AWStats in order to track their traffic.

Personally, I don’t have much experience dealing with log files other than just using vim or grep to find the info I need. Anyways, I decided to wear my Espresso machine beanie and take a walk in NYC during the first snow day.

First, you need to SSH to your Linux server and install the perl dependencies:

sudo yum install perl-Time-HiRes perl-libwww-perl 

Next, download the latest version of AWStats or use yum to install it. This is what I did to get the latest AWStats version:

wget https://downloads.sourceforge.net/awstats/awstats-7.9.tar.gz 

Extract the tar.gz

tar xvzf awstats-7.9.tar.gz 

Move the extracted folder to Apache root directory:

mv awstats-7.9 /var/www/html/awstats

Configure AWStats

Make a new directory in:

mkdir /etc/awstats

Then copy the sample config file from the awstats folder you moved above to your /etc/awstats:

sudo cp /var/www/html/awstats/wwwroot/cgi-bin/awstats.model.conf /etc/awstats/awstats.sample.com.conf 

Replace the name awstats.sample.com with your domain name/hostname.

Edit the new config you moved above. Use the text editor of your choice:

sudo vim /etc/awstats/awstats.sample.com.conf 

There are 3 main options I configure for my case:

LogFile: Path to your apache log file

SiteDomain: Domain name of your site.

DirData: Location AWStats will store data.

Configure Apache

Create a new host file:

sudo vim /etc/httpd/conf.d/awstats.<your_domain>.conf

You can use this sample conf file:

<VirtualHost *:80>
  ServerName awstats.example.com
  DocumentRoot /var/www/html/awstats/wwwroot
  ScriptAlias /awstats/ /var/www/html/awstats/wwwroot/cgi-bin/
  <Directory /var/www/html/awstats/wwwroot/cgi-bin/>
    Options ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
  <Directory /var/www/html/awstats/wwwroot/>
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Save changes. You may need to reload Apache.

Go back to:

cd /var/www/html/awstats/ 

and run the perl script in there:

perl tools/awstats_updateall.pl now-config=<your_domain>.com -awstatsprog=./wwwroot/cgi-bin/awstats.pl 

Finally, access your stats using this URL:

http://awstats.<your_domain.com>/awstats/awstats.pl

You should see some data displaying:

Configure AWStats RedHat server
Configure AWStats RedHat server

Hopefully this can help anybody to install and configure AWstats on your server. There are some tasks you should consider. Setup a cronjob to autoupdate AWStats database so it can access new log files. We should place the two commands above into a cronjob:

#maybe run every hour or daily?
0 * * * * cd /var/www/html/awstats/ && perl tools/awstats_updateall.pl now -config=example.com -awstatsprog=./wwwroot/cgi-bin/awstats.pl

Change the cronjob as needed. Thanks!