How to Install AWStats with Apache Web Server for Analysis and Monitoring

In this post, I will go into details of installing AWStats with Apache web server for Monitoring and web server log analysis.

AWStats is a free powerful and featureful tool that generates advanced web, streaming, FTP, or mail server statistics, graphically. This log analyzer works as a CGI or from the command line and shows you all 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 can analyze log files from all major server tools like Apache log files (NCSA combined/XLF/ELF log format or common/CLF log format), IIS (W3C log format) and many other types of servers.

AWStats is an Open Source tool released under a GPL license and is free for users in both commercial and non-commercial environments.

Install Apache

Before I install AWStats, I need to have Apache installed. On Debian or Ubuntu, I will install the Apache web server using the following commands.

root@mars:~# sudo apt install apache2

This will install Apache on the local machine, listening on port 80.

Now I need to enable the CGI module for Apache as it is required for AWStats.

root@mars:~# sudo a2enmod cgi

Finally, restart the Apache web server.

root@mars:~# sudo service apache2 restart

Let’s make sure Apache is working. Test the installation by typing the following curl command.

root@mars:~# curl http://localhost -I
HTTP/1.1 200 OK
Date: Tue, 15 Nov 2022 03:48:41 GMT
Server: Apache/2.4.41 (Ubuntu)
Last-Modified: Mon, 14 Nov 2022 23:47:14 GMT
ETag: "155-5ed76dbde4904"
Accept-Ranges: bytes
Content-Length: 341
Vary: Accept-Encoding
Content-Type: text/html

Curl with the -I options only shows all the headers. The first line HTTP/1.1 200 OK shows that Apache server is up and running.

Install and Configure AWStats

With Apache installed and the CGI module enabled I am ready to install AWStats and its pre-requisite PERL programming language.

Install AWStats and PERL

Use the following commands to install these components.

root@mars:~# sudo apt install perl
root@mars:~# sudo apt install awstats

By default, AWStats is set up to analyze logs for localhost on 127.0.0.1. The Apache log file it uses is /var/log/apache2/access.log.

Configure AWStats

Now that our default AWStats install is complete, the next step is to install the site scripts to your website root folder.

### Copy the cgi script to your website root folder. For localhost on Ubuntu it is /var/www/html ###
root@mars:~# sudo cp -r /var/lib/cgi-bin /var/www/html/

### Change owner on the script directory
root@mars:~# sudo chown www-data:www-data /var/www/html/cgi-bin/

### Change permission on the script directory
root@mars:~# sudo chmod -R 755 /var/www/html/cgi-bin/

With all the files in place, I will run the script to update AWStats data. Type the following line in the terminal.

root@mars:~# /usr/lib/cgi-bin/awstats.pl -config=localhost -update

This will update the stats from an existing /var/log/apache2/access.log file.

Viewing and Testing AWStats Log Analysis Results

In an earlier step, I copied the AWStats UI scripts into the website folder at /var/www/html/cgi-bin. You can use the URL http://localhost/cgi-bin/awstats.pl?config=localhost in the browser to view the AWStats analytics web page.

In my case, I installed AWStats on a virtual machine with minimal activity so there is not much data. But if you have a big log file you will be able to see a lot more information. In either case, though the layout should look similar to what is shown in the image below.

AWStats with Apache Analytics view for Domain.
AWStats with Apache Analytics view for Domain.

Setting up Auto-Update of AWStats Analytics Using Cron

To get updated stats you have to run the awstats.pl script. This can get tedious and it is a job that should be automated. Well, I will do exactly this in this section.

Edit the /etc/crontab file and add the following line to run the awstats.pl script every 15 minutes.

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

Install AWStats for a Different Domain

Installing AWStats for a new virtual domain is similar to what we have done earlier.

Let’s assume for this step that your domain example.com is already setup on the Apache web server with the website files in the folder /var/www/example. [Replace example.com with your actual domain name]. Run the following command in the order shown.

### Create new domain config file
root@mars: ~# sudo cp /etc/awStats/awstats.conf.local /etc/awstats/example.conf

### Copy the cgi script to your website root folder. For localhost on Ubuntu it is /var/www/html ###
root@mars:~# sudo cp -r /var/lib/cgi-bin /var/www/example/

### Change owner on the script directory
root@mars:~# sudo chown www-data:www-data /var/www/example/cgi-bin/

### Change permission on the script directory
root@mars:~# sudo chmod -R 755 /var/www/example/cgi-bin/

The above command created a new config for the domain and copies all script files to the website root folder. Next, I need to edit the config file. Open your favorite editor and copy the following lines

# Change to Apache log file, by default it's /var/log/apache2/access.log
LogFile="/var/log/apache2/example-access.log"

# Change to the website domain name
SiteDomain="example.com"
HostAliases="example.com www.example.com"
DirCgi="/cgi-bin"

# Setting this to 1 allows AWStats to update statistics from the browser
AllowToUpdateStatsFromBrowser=1

With all changes in place. Run the AWStats data update script.

root@mars:~# /usr/lib/cgi-bin/awstats.pl -config=example.com -update

Now go to the URL http://localhost/cgi-bin/awstats.pl?config=example.com to view the results.

Understanding AWStats Configuration File Parameters

There are many configuration parameters you can set in your domain configuration file. Some of the important ones are listed below.

LogFile

This points to the Apache web server access.log file location. If you are using separate log files for different domains then you need to set this value pointing to the log file.

LogFormat

Enter here your log format (Must match your web server config. Possible values for Apache are 1 and 4. While it is 2 for IIS.
1 – Apache combined log format (NCSA combined/XLF/ELF log format)
2 – IIS or ISA format (IIS W3C log format).
4 – Apache or Squid native common log format (NCSA common/CLF log format)

SiteDomain

SiteDomain” must contain the main domain name, or the main intranet web server name used to reach the website. If you share the same log file for several virtual web servers, this parameter is used to tell AWStats to filter record that contains records for this virtual host name only.

HostAliases

Enter here all other possible domain names, addresses or virtual host aliases someone can use to access your site. Try to keep only the minimum number of possible names/addresses to have the best performances.

DNSLookup

If you want to have hosts reported by name instead of IP address, AWStats need to make reverse DNS lookups (if not already done in your log file). With DNSLookup to 0, all hosts will be reported by their IP addresses and not by the full hostname of visitors (except if names are already available in the log file).

If you want/need to set DNSLookup to 1, don’t forget that this will reduce dramatically AWStats update process speed. Do not use on large websites. The default value is 2 which means that the DNS lookup is made only from a static DNS cache file.

DirData

This parameter specifies where AWStats stores processed log files data. I have set it to.

DirData="/var/lib/awstats"

DirCGI

This is a relative or absolute web URL of your AWStats cgi-bin directory. Since I installed the folder in {web-root}/cgi-bin my entry looks like this:

DirCgi="/cgi-bin"

AllowToUpdateStatsFromBrowser

If set to 1 then AWStats adds a button on the web report to allow updates of statistics from the web page. Otherwise, the data is updated whenever the CGI script is run. The default value is 0, which does not provide an update button.

DefaultFile

This specifies the default index file name of your website. The default listed names are index.php and index.html. If you are using a custom extension for example dir.wow, then you need to update this line.

DefaultFile="index.php index.html dir.wow"

Conclusion

For other guides and posts on Apache check out our Apache web server page.


FAQ

What is Apache AWStats?

AwStats is a handy 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 graphically generates advanced web, streaming, FTP, or mail server statistics.

What it is the Best free IIS log Analyzer Tools?

AwStats is a pretty good tool to use for analyzing IIS web server logs. You can analyze IIS logs with AwStats by using the IIS access and error logs in a similar manner as to how AwStat works with Apache web server. Just make sure that you are using standard log file format with IIS.

One way to do this is to enable CGI for IIS and create a script to run AwStats against each log file, if you are going to automate the process.

The other way is to use a file copy script job to AwStats location and then kick off the analysis script.

Please keep on checking this page as I will add a link to a complete tutorial on using AwStats with Microsoft IIS.

Where does AWStats store data files?

AWStats statistics database files are saved in directory defined by the DirData parameter in configuration file.

What does AWStats Stand for?

AWStats (Advanced Web Statistics) is an open source Web analytics reporting tool, suitable for analyzing data from Internet services such as web, streaming media, mail, and FTP servers.

How do I Access AWStats?

If you have AWStats installed on localhost You can access webpage using the URL:

http://localhost/cgi-bin/awstats.pl?config=localhost
Where is the AWStats Config File?

Where is AWStats config file?

On Ubuntu the AWStats configuration files are in the folder /etc/awstats/*.conf.

Is AWStats GDPR Compliant?

Keep in mind you will need to develop code that would encrypt/decrypt the txt files eveyrtime you want to update the data. From my research, AWStats today is not GDPR compliant

What are Hits in AwStats?

Hits: total number of data chunks delivered to visitors. For example a single page would count as two hits if it contained text and a single graphic.

Leave a Comment