Jump toUpdate content

How to deploy AwStats

Reviewed on 10 May 2021Published on 03 December 2018
  • compute
  • AwStats
  • FTP
  • Apache

AwStats Overview

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 an open-source Web analytics reporting tool that generates advanced web, streaming, FTP or mail server statistics graphically.

It is a complete enterprise grade server and log monitoring software that works as a CGI (Common Gateway Interface) or from command line and which shows you all possible information your log contains, in few graphical web pages, often and quickly.

AwStats uses log file analysis to analyze log files from most web servers including Apache, IIS and many other web servers.


Installing Apache

Before installing AwStats server packages, make sure Apache2 HTTP server is installed.

apt update
apt install apache2

Installing and Configuring AwStats Package

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

  1. Install AwStats package

    apt-get install awstats
  2. Enable the CGI module in Apache

    a2enmod cgi
  3. Restart Apache

    systemctl restart apache2
  4. Duplicate the AwStats default configuration file to one with your domain name

    cp /etc/AwStats/awstats.conf /etc/awstats/domain-example.conf
  5. Edit the your AwStats domain name configuration file

    nano /etc/awstats/domain-example.conf
  6. Update the settings shown below

    # Change to Apache log file, by default it's /var/log/apache2/access.log

    # Change to the website domain name
    HostAliases="www.domain-example localhost"

    # When this parameter is set to 1, AwStats adds a button on report page to allow to "update" statistics from a web browser
  7. Save and close the file

  8. Build your initial statistics which is generated from the current logs on your server

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

    which returns

    Create/Update database for config "/etc/awstats/awstats.conf" by AwStats version 7.6 (build 20161204)
    From data in log file "/var/log/apache2/access.log"...
    Phase 1 : First bypass old records, searching new record...
    Searching new records from beginning of log file...
    Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
    Jumped lines in file: 0
    Parsed lines in file: 5
    Found 0 dropped records,
    Found 0 comments,
    Found 0 blank records,
    Found 0 corrupted records,
    Found 0 old records,
    Found 5 new qualified records.

Configuring Apache For AwStats

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.

cp -r /usr/lib/cgi-bin /var/www/html/
chown www-data:www-data /var/www/html/cgi-bin/
chmod -R 755 /var/www/html/cgi-bin/

Testing AwStats

Now you can access your AwStats by visiting the url http://your-server-ip/cgi-bin/awstats.pl?config=test.com

which displays

Setting-up Cron Job 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.

  1. Edit the /etc/crontab file

    nano /etc/crontab
  2. Add the following line to tell AwStats to update every ten minutes

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