How to Configure Awstats
AWStats (Advanced Web Statistics) is a free web analytics reporting tool. It 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 is the most widely used log analyzer program with Apache Web Servers on Respective Enterprise Linux.
This tutorial shows how to install and configure AWStats for Apache. You need to follow all the steps carefully to setup the AWStats for Apache.
NOTE: The mentioned steps are performed on CentOS 7 server.
STEP 1. Install AWSstats.
sudo yum install awstats
STEP 2. Configure AWStats for Apache
AWStats creates an Apache configuration file /etc/httpd/conf.d/awstats.conf
by default. If you want to access AWStats from all networks, then you will need to update the settings as follows.
<Directory "/usr/share/awstats/wwwroot">
Options None
AllowOverride None
<IfModule mod_authz_core.c>
# Apache 2.4
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
# Order allow,deny
# Allow from 127.0.0.1
# Allow from ::1
Require all granted
</IfModule>
</Directory>
Restart the Apache service to reload new settings
sudo systemctl restart httpd
Here, we will create a configuration file for the example.com
domain.
NOTE: You need to create a separate configuration file for each website for which you wish to view statistics.
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, make the following changes in the config file
sudo vim /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"
Save and close the file. Restart the Apache service to reload the new settings:
sudo systemctl restart httpd
After doing the above changes, you need to build your initial statistics, which will be generated from the current logs on your server.
You can use this command for it:
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>
STEP 3. 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.)
http://your.server.ip/awstats/awstats.pl?config=example.com/
NOTE: As AWStats is allowed to access from all networks, it is advised to add HTTP Authentication on AWStats.
To add HTTP Authentication to AWStats, follow the below steps :
1. This command creates a new password file and sets the password for the “admin” user:
sudo htpasswd -c /etc/apache2/.htpasswd admin
2. Enable HTTP authentication in AWS
Edit /etc/httpd/conf.d/awstats.conf
and add the following in the file.
<Location /awstats>
AuthType Basic
AuthName "AWStats Admin Access Required"
AuthUserFile "/etc/httpd/.htpasswd"
require valid-user
</Location>
Save and exit the file & restart apache service
sudo systemctl restart
Now, It will prompt for username & password when you will try to access AWStats in a browser.
Leave a Reply