Table of Contents
- Install the AWStats package
- Configure AWStats for Apache
- Create an AWStats configuration file
- Set up Cron to update the logs
- Access AWStats in a browser
AWStats is a free (and very useful) web analytics reporting tool which generates advanced web, streaming, FTP, or mail server statistics. AWStats analyzes server log files and produces HTML reports in a nice graphical display.
The AWStats log analyzer works as either a CGI program or from the command line. It presents all the information contained your log files in a few easy-to-read web pages. It supports most web server log file formats including Apache and IIS.
In this tutorial, I will explain how to install and configure AWStats on CentOS 7
- A server running CentOS v. 7 with Apache installed
- A static IP Address for your server
Install the AWStats package
By default the AWStats package is not available in the CentOS 7 repository. You will need to install the EPEL Yum repository on the server.
You can install and enable the EPEL repository by running the following command:
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
Next, install the
awstats package using Yum. This will also install all other required dependencies.
sudo yum --enablerepo=epel install awstats
Configure AWStats for Apache
By default AWStats creates an Apache configuration file
/etc/httpd/conf.d/awstats.conf. If you need to access AWStats from the network, then you need to update the
Allow from and
Require with your server's IP address.
You can do this by editing the AWStats config file:
sudo nano /etc/httpd/conf.d/awstats.conf
Update the following lines as shown below. Substitute your own IP address for the sample address 192.168.1.0:
<Directory "/usr/share/awstats/wwwroot"> Options None AllowOverride None <IfModule mod_authz_core.c> # Apache 2.4 Require ip 192.168.1.0/24 </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order allow,deny Allow from 127.0.0.1 Allow from 192.168.1.0/24 </IfModule> </Directory>
Restart the Apache service to reload new settings
sudo apachectl restart
Create an AWStats configuration file
You need to create a configuration file for each website for which you wish to view statistics. Here, we will create a configuration file for the
First, create a copy of the default AWStats configuration file with your domain name:
sudo cp /etc/awstats/awstats.localhost.localdomain.conf etc/awstats/awstats.example.com.conf
Next you will need to make some changes in the config file:
sudo nano /etc/awstats/awstats.example.com.conf
Update the following lines:
# Change to Apache log file, by default it's /var/log/apache2/access.log LogFile="/var/log/httpd/access.log" # Change to the website domain name SiteDomain="example.com" HostAliases="www.example.com localhost 127.0.0.1" # When this parameter is set to 1, AWStats adds a button on report page to allow to "update" statistics from a web browser AllowToUpdateStatsFromBrowser=1</code></pre>
Save and close the file. Restart the Apache service to reload the new settings:
sudo apachectl restart
After these changes, you need to build your initial statistics, which will be generated from the current logs on your server.
You can do this using:
sudo /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=example.com -update
The output will look something like this:
From data in log file "/var/log/httpd/access_log"... Phase 1 : First bypass old records, searching new record... Direct access after last parsed record (after line 209) Jumped lines in file: 209 Found 209 already parsed records. Parsed lines in file: 0 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 0 new qualified records.</code></pre>
Set up Cron to update the logs
It is a good idea to set up a cron job to regularly update the AWStats database using newly-created log entries. This will save you time, as well as ensure that the stats are updated on a regular basis.
You can do this by editing
sudo nano /etc/crontab
Add the following line:
*/30 * * * * root /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=example.com -update
Save and close the file.
Access AWStats in a browser
Now you can access your AWStats by visiting the URL:
(Change the domain name at the end of the URL to match your own.)
It will show you a result page like this: