How to Set Up AWStats On Ubuntu Server

AWStats is an open-source Web analytics reporting tool that generates advanced web, streaming, FTP or mail server statistics graphically. This log analyser works as a CGI or from command line and shows you all the possible information your log contains in a few graphical web pages. It uses a partial information file to be able to process large log files often and quickly. It supports most web server log file formats including Apache, IIS and many other web server log formats.

This article will help you to install and configure AWStats on Ubuntu.

Install AWStats Package

By default, AWStats package is available in the Ubuntu repository.

You can install it by running:

sudoapt-get install awstats

Next you will need to enable the CGI module in Apache.

You can do this by running:

sudo a2enmod cgi

Now, restart Apache to reflect the changes.

sudo/etc/init.d/apache2 restart

Configure AWStats

You need to create a configuration file for each domain or website you wish to view statistics for. In this example we will create a configuration file for “test.com“.

You can do this by duplicating the AWStats default configuration file to one with your domain name.

sudocp/etc/awstats/awstats.conf /etc/awstats/awstats.test.com.conf

Now, you need to make some changes in the config file:

sudonano/etc/awstats/awstats.test.com.conf

Update the settings shown below:

# Change to Apache log file, by default it's /var/log/apache2/access.logLogFile="/var/log/apache2/access.log"# Change to the website domain nameSiteDomain="test.com"HostAliases="www.test.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 browserAllowToUpdateStatsFromBrowser=1

Save and close the file.

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/lib/cgi-bin/awstats.pl -config=test.com -update

The output will look something like this:

Configure Apache For AWStats

Next, you need to configure Apache2 to show these stats. Now copy the content of the “cgi-bin” folder to the default document root directory of your Apache installation. By default, this is in the “/usr/lib/cgi-bin” folder.

Test AWStats

Now you can access your AWStats by visiting the url “http://your-server-ip/cgi-bin/awstats.pl?config=test.com.” It will show you a results page like this:

Set Up Cron to Update Logs

It is recommended to schedule a cron job to regularly update the AWStats database using newly created log entries, so the stats get updated on a regular basis. This will also save your time.

To do this you need to edit the “/etc/crontab” file:

sudonano/etc/crontab

Add the following line that tells AWStats to update every ten minutes.

*/10**** root /usr/lib/cgi-bin/awstats.pl -config=test.com -update

Save and close the file.

Conclusion

AWStats is a very useful tool that can give you an overview of what is happening on your website and assist with site analysis. It is very easy to install and configure. Feel free to comment below if you have any questions.