How To Install AWStats with Apache On FreeBSD

AWStats is widely used by people for its ability to analyze Apache log files, email log files, and FTP log files in static or dynamic HTML report formats. Not only that, AWStats can process separate log files for clusters. One of the reasons why you should choose AWStats is because of its fast speed and ability to handle large log formats. Additionally, its functionality can be extended with plugins.

AWStats (Advanced Web Statistics) is an open source web analytics tool that analyzes and generates comprehensive reports on web server log files such as Apache or NGINX. All visitor information on the website and various aspects of web traffic are neatly arranged and easy to read. To do all that, AWStats requires a server log file, so it is important for me to set up a server log file on Apache or NGINX.

AWStats is a very powerful and useful software that allows webmasters to count visits to the websites they manage. This tool is built with Perl and was a very popular choice before Google launched the Google Analytics tool. However, currently not everyone uses Google Analytics services and it can even be difficult to utilize it for both companies and government agencies. This is AWStats in the modern web world that can be used with Apache but also with Nginx.

1. Pre-requisites

OS: FreeBSD 13.2
Apace24 with mod_perl
IP Address
Hostname: ns6

2. Setup Apache mod_perl

Apache Perl is an integrated project that brings together the Perl programming language and the Apache web server. By connecting the Perl runtime library to the server and providing an object-oriented Perl interface to the server's C language API. These pieces are glued together seamlessly by the `mod_perl' server plugin, making it possible to write Apache modules entirely in Perl. Additionally, a persistent interpreter embedded in the server avoids the overhead of starting an external interpreter and the Perl start-up (compilation) time penalty.

This Mod_Perl is used by AWStats to connect to the Apache server. With Mod_Perl the server response time becomes faster. The following is a guide to installing mod_perl on Apache24.
root@ns6:~ # cd /usr/ports/www/mod_perl2
root@ns6:/usr/ports/www/mod_perl2 # make install clean
root@ns6:/usr/ports/www/mod_perl2 # cd /usr/ports/databases/p5-DBI
root@ns6:/usr/ports/databases/p5-DBI # make install clean
root@ns6:/usr/ports/databases/p5-DBI # cd /usr/ports/www/p5-Apache-DBI
root@ns6:/usr/ports/www/p5-Apache-DBI # make install clean
After that, add the script below to the file "/usr/local/etc/apache24/httpd.conf".

<Location /cgi-bin/*.pl>
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
PerlSendHeader On
Options ExecCGI
Require all granted
<Location /cgi-bin/*.cgi>
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
PerlSendHeader On
Options ExecCGI
Require all granted

Then, you activate the mod_perl module in the file "/usr/local/etc/apache24/modules.d/260_mod_perl.conf"

#LoadModule perl_module        libexec/apache24/

Remove the sign "#"

LoadModule perl_module        libexec/apache24/

Also Read:

3. Setup awstats

The official documentation for setting up AWStats can be found here. However, to install AWStats on FreeBSD and configure it we will use the general configuration with default scripts. The default AWStats installation with the ports system can be found at /usr/ports/www/awstats. Follow the steps below.
root@ns6:~ # cd /usr/ports/www/awstats
root@ns6:/usr/ports/www/awstats # make install clean
The results of the installation above will produce a new folder "/usr/local/www/awstats"We will use the IP address to connect with the Apache24 server, therefore copy the files awstats.model.conf to awstats.
root@ns6:~ # cd /usr/local/www/awstats/cgi-bin
root@ns6:/usr/local/www/awstats/cgi-bin # cp awstats.model.conf awstats.
Change the Alias for CGI scripts in the "/usr/local/etc/apache24/httpd.conf" file.

ScriptAlias /cgi-bin/ "/usr/local/www/apache24/cgi-bin/"


ScriptAlias /cgi-bin/ "/usr/local/www/awstats/cgi-bin/"

Next, create awstats permissions to the Apache24 server by adding the script below to the "/usr/local/etc/apache24/httpd.conf" file.

Alias /awstatsclasses "/usr/local/www/awstats/classes/"
Alias /awstatscss "/usr/local/www/awstats/css/"
Alias /awstatsicons "/usr/local/www/awstats/icon/"

<Directory "/usr/local/www/awstats">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all

We will now edit the file "/usr/local/www/awstats/cgi-bin/awstats.", and change following parameters.

HostAliases=" ns6"

Create log file and run the chown and chmod commands on the folder.
root@ns6:~ # touch /var/log/httpd/awstats.log
root@ns6:~ # chown -R www:www /usr/local/www/awstats/ && chown -R www:www /var/log/httpd/
root@ns6:~ # chmod -R 777 /usr/local/www/awstats/
Since the way awstats works is reading log files, let's go ahead and process the log file for the domain with IP Address
root@ns6:~ # cd /usr/local/www/awstats/cgi-bin
root@ns6:/usr/local/www/awstats/cgi-bin # perl -update -config=
Create/Update database for config "./awstats." by AWStats version 7.9 (build 20230108)
From data in log file "/var/log/httpd/mylog.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 0
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 0 new qualified records.
After that, to execute all the configurations above, you restart the Apache server.
root@ns6:~ # service apache24 restart
The final step of our project this time is to carry out ASWTATs testing. If you haven't missed anything in the configuration above and you have set it according to the instructions above, you should be able to open AWStats in the Yandex or Google Chrome web browser. In the address bar menu of your web browser, enter "" and the results will look like the image below.

Take a look at the image above, all the data is not displayed or is empty, because we are using a private IP If you have a website on a personal computer, replace the private IP address with your domain, surely all the data will be displayed by awstats. The method is the same, you just replace the private IP with your domain name.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post