Table of Contents

How to install AWStats with Apache on Debian 12/Bookworm

Install AWStats

Run the following command:

apt install awstats

This will start the installation process, resolve dependencies and install the required packages for you.

Optional: In order to get GeoIP information you can install the following Perl packages:

apt install libgeo-ip-perl libgeo-ipfree-perl

Configure AWStats

Once the installation routine is completed, edit the file awstats.conf as follows:

LogFile="/var/log/apache2/access.log"
LogFormat=1
SiteDomain="your-domain.com"
HostAliases=”www.your-domain.com your-domain.com”
DNSLookup=0
AllowFullYearView=3
LoadPlugin="tooltips"

Configure Apache for AWStats

Edit the Apache configuration file /etc/apache2/conf-available/awstats.conf like so

vi /etc/apache2/conf-available/awstats.conf

Paste the following content

Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

Save and exit the configuration file.

To enable this configuration run

ln -s /etc/apache2/conf-available/awstats.conf /etc/apache2/conf-enabled/awstats.conf

Enable the “cgi” module in Apache

/usr/sbin/a2enmod cgi

Implement the changes by restarting Apache

systemctl restart apache2

You can see how the installation is progressing by pointing your web browser to:

http://your-domain.xyz/cgi-bin/awstats.pl

The top line should display the time when statistics were updated. It probably reads 'Never updated'. Now you need to manually trigger your first update

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

Now you should get some output like

Create/Update database for config "/etc/awstats/awstats.conf" by AWStats version X (build X)
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: X
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found X new qualified records.

Secure Your AWStats via .htaccess

A basic, simple way of restricting access is to set up a http password. Open your apache2 configuration file

vi /etc/apache2/sites-available/your-domain.com.conf

Paste the content as shown below:

<Directory /usr/lib/cgi-bin/>
    Options +ExecCGI
    AddHandler cgi-script .cgi
    AuthType Basic
    AuthName 'Password Protected Area'
    AuthUserFile '/usr/lib/cgi-bin/.htpasswd'
    Require valid-user
</Directory>

If you don’t have a password that can be used for this purpose, the command htpasswd can do it for you.

htpasswd -cb /usr/lib/cgi-bin/.htpasswd admin mypassword