Installing AWStats (Advanced Web Statistics) on Ubuntu 18.04 with Apache
In this tutorial, we are going to learn how to install AWStats on Ubuntu 18.04 server with Apache web server. AWStats (Advanced Web Statistics) is a free, open-source Web analytics software written in the Perl programming language. Web analytics software are used by webmasters to know how many visitors are on a site in a day/week/month, what web browser they are using, etc. It is a crucial piece of software to help grow their websites.
AWStats Features
- It can generate user statistics from server log files. Web, streaming, ftp or mail server are supported.
- It can show you number of visits, and unique visitors, visit duration.
- display information about visitors (OS, browser, IP address, screen size, search engine, keyphrase and keywords used to find your website)
- It works from command line and as CGI.
To see a full list of features, please check the official AWStats website.
Installing AWStats on Ubuntu 18.04 with Apache
First, you need to install Apache web server. Run the following command to install Apache from the default Ubuntu repository.
sudo apt install apache2
Then install AWStats. The two Perl package is used to get GeoIP information.
sudo apt install awstats libgeo-ip-perl libgeo-ipfree-perl
AWStats can collect statistics from Apache log files. It’s recommended to create separate log files for each Apache virtual host.
Configuring Apache Virtual Host
Edit your Apache virtual host file.
sudo nano /etc/apache2/sites-available/example.com.conf
First, you need to enable logging in your virtual host by adding the following lines in the <VirtualHost>
tag.
ErrorLog ${APACHE_LOG_DIR}/exmaple.com_error.log CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
Then add the following lines to the end of the file before the closing </VirtualHost>
tag.
Alias /awstatsclasses "/usr/share/awstats/lib/" Alias /awstats-icon/ "/usr/share/awstats/icon/" Alias /awstatscss "/usr/share/doc/awstats/examples/css" ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ ScriptAlias /awstats/ /usr/lib/cgi-bin/ Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Save and close the file. Run the following command to enable CGI module and restart Apache for the changes to take effect.
sudo a2enmod cgi sudo systemctl restart apache2
The AWStats web interface will be accessible at example.com/cgi-bin/awstats.pl
, but we need to make a little more configuration to make it work.

Configuring AWStats
The main configuration file is /etc/awstats/awstats.conf
. To keep your modifications when the awstats package gets updated, we copy it to a new file.
sudo cp /etc/awstats/awstats.conf /etc/awstats/awstats.exmaple.com.conf
Then edit the new file.
sudo nano /etc/awstats/awstats.example.com.conf
First, you need to change the value of LogFile
to the file name used by your Apache virtual host.
LogFile="/var/log/apache2/example.com_access.log"
Next, find the following line.
LogFormat=4
Because we used the combined
log format in Apache virtual host, so we need to change the value to 1.
LogFormat=1
Then, add your domain name in the SiteDomain
parameter. If your website uses a sub-domain, like blog.example.com, then add blog.example.com to SiteDomain
parameter.
SiteDomain="blog.example.com"
Also, add your domain name to the HostAliases
parameter.
HostAliases="blog.example.com localhost 127.0.0.1"
Save and close the file. Next, we need to allow www-data
user to read the Apache logs by using the following command.
sudo setfacl -R -m "u:www-data:rx" /var/log/apache2/
The AWStats web interface is now accessible (example.com/cgi-bin/awstats.pl
).

The AWStats cron job (/etc/cron.d/awstats
) by default updates statistics every 10 minutes. AWStats stores its data under /var/lib/awstats/
directory.
Restricting Access to AWStats Web Interface
By default, the AWStats web interface is publicly accessible. To restrict access, we can enable basic password authentication with Apache web server. Run the following command to set a password for user admin
. /etc/apache2/htpasswd
file is used to store usernames and password
sudo htpasswd -c /etc/apache2/htpasswd admin
Then edit the Apache virtual host file.
sudo nano /etc/apache2/sites-available/example.com.conf
Add the following lines.
<Directory "/usr/lib/cgi-bin/"> AuthUserFile /etc/apache2/htpasswd AuthName "Please Enter Your Password" AuthType Basic Require valid-user </Directory>
Save and close the file. Then restart Apache for the changes to take effect.
sudo systemctl restart apache2
If you access the AWStats web interface again, you will be asked to enter username and password.
