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/

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, but we need to make a little more configuration to make it work.

awstats ubuntu 18.04

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/

Then edit the new file.

sudo nano /etc/awstats/

First, you need to change the value of LogFile to the file name used by your Apache virtual host.


Next, find the following line.


Because we used the combined log format in Apache virtual host, so we need to change the value to 1.


Then, add your domain name in the SiteDomain parameter. If your website uses a sub-domain, like, then add to SiteDomain parameter.


Also, add your domain name to the HostAliases parameter.

HostAliases=" localhost"

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 (

awstats ubuntu how to

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/

Add the following lines.

<Directory "/usr/lib/cgi-bin/">
    AuthUserFile /etc/apache2/htpasswd
    AuthName "Please Enter Your Password"
    AuthType Basic
    Require valid-user

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.

awstats ubuntu install


I hope this tutorial helped you install AWStats on Ubuntu 18.04 with Apache web server. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 3 Average: 5]

15 Responses to “Installing AWStats (Advanced Web Statistics) on Ubuntu 18.04 with Apache

  • Works perfectly for me.

  • Thanks alot brotherman, works like a charm

  • Works as a charm even on raspberry.

  • Frederic
    4 years ago

    Hello Xiao,

    I’ve followed your Apache tutorial so my vhost conf file contains 2 different sections (http and https) I assume this the SSL log file I need to set into /etc/awstats/ right ?

    Thank you

  • Hi,

    Thank you for the tutorial.
    How would we configure the awstats.conf file or the vhost.conf file when we have multiple sites running as virtual hosts?

  • For those installing under Ubuntu 20.04 you must install the ACL package “sudo install acl” for the setfacl function to work.

  • I’m not that much of a internet reader to be honest but your blogs really nice, keep it up!
    I’ll go ahead and bookmark your website to come back in the future.
    All the best

  • Howdy this is kind of of off topic but I was wondering if blogs
    use WYSIWYG editors or if you have to manually code with HTML.

    I’m starting a blog soon but have no coding expertise so I wanted to get advice from
    someone with experience. Any help would be greatly appreciated!

  • Howdy are using WordPress for your blog platform?
    I’m new to the blog world but I’m trying to get
    started and set up my own. Do you require any coding knowledge to make your own blog?
    Any help would be greatly appreciated!

  • Very good write-up. I certainly appreciate this site.
    Continue the good work!

  • Great blog here! Also your website loads up fast! What
    host are you using? Can I get your affiliate link to your host?
    I wish my website loaded up as fast as yours lol

  • You’ve written an excellent post, and you’ve shared it
    with us. Your article provided me with some unique and useful
    knowledge. I appreciate you sharing this text with us.

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here