How to install AWStats on Ubuntu Linux

AWStats is a powerful and featureful tool to analyze apache access logs. Using AWStats, you can view various stats 404, etc. Here are steps to install AWStats on Ubuntu Linux:

Install AWStats package on Ubuntu Linux

$ sudo apt-get install awstats

To see files in package awstats:

$ dpkg -L awstats

AWStats configuration

Edit awstats config file at location /etc/awstats/awstats.conf.local using sudo. Depending upon you log file name and domain name change the value of LogFile and SiteDomain.

Case 1

You log file is access_log


Case 2

You log file is access_log.YYYY-MM-DD


AWStats crons

As part of the package installation AWStats also installs cron which runs as www-data to populate data in /var/lib/awstats/. To view the cron entries, run the following:

$ cat /etc/cron.d/awstats

*/10 * * * * www-data [ -x /usr/share/awstats/tools/ ] && /usr/share/awstats/tools/

# Generate static reports:
10 03 * * * www-data [ -x /usr/share/awstats/tools/ ] && /usr/share/awstats/tools/

You may want to change MAILTO value to you email address.

AWStats data location

Since cron runs every 10 min, wait for few minutes (max 10 minutes) and you should be able to see data files in /var/lib/awstats/

$ sudo ls -l /var/lib/awstats/
total 24
-rw-rw-r-- 1 www-data www-data 15723 Nov 27 17:10 awstats112015.txt
-rw-rw-r-- 1 www-data www-data  7014 Nov 27 17:10 dnscachelastupdate.hash

AWStats apache configuration

Not setup apache conf by copying and editing sample apache conf present in awstats package.

$ sudo cp  /usr/share/doc/awstats/examples/apache.conf /etc/apache2/conf-enabled/awstats.conf

Replace ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ in awstats.conf with the following line.

ScriptAlias /awstats/   /usr/lib/cgi-bin/

AWStats ui

Now check the config syntax and if everything is fine, then restart apache.

$ sudo apache2ctl configtest
$ sudo apache2ctl restart

Now visit your awstats site at the url /awstats/ Here is how it should appear:

Add basic apache auth to AWStats

We should also add auth to AWStats urls. Create an auth files using htpasswd. We’ll create user awstats in file /etc/auth_awstats with desired password.

$ sudo htpasswd -c /etc/auth_awstats awstats

Add the following config in awstats.conf to enable http basic auth:

<LocationMatch /(awstats/|cgi-bin/>
  AuthType Basic
  AuthName "Restricted Resource"
  AuthBasicProvider file
  AuthUserFile /etc/auth_awstats
  Require valid-user

Note that we added cgi-bin/ also in above config. In case your apache server has /cgi-bin/ configured, it may make /cgi-bin/ accessible. So we should protect that also.

AWStats – check if auth is working

Restart apache for the config to take effect. Now when you access the url /awstats/, you will see username and password prompt as shown below:

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments