awstats: 7.7 (upstream)
Debian: stretch (9.11)
apache2: 2.4.25
perl: 5.24.1
AWstats is a popular and powerfull Apache2 access-logfile analyser.
This document describes manual installation of “awstats”. Although there is a “awstats” Debian package, manual installation has the advantage of always using the latest upstream version and gives you more control over the installation process.
Download the .tar.gz file or the .zip archive.
Extract the archive in “/usr/local”:
# cd /usr/local # tar --no-same-owner -xzf _path_to_archive/awstats-7.7.tar.gz # mv awstats-7.7 awstats
Do NOT run the awstats_configure.pl configure script!
It doesn't handle the Debian apache2 configuration very well.
Central to the configuration of awstats is the concept of virtual hosting. Each virtual host must have a distinct access logfile:
/etc/apache2/sites-available/vhostX.conf:
CustomLog ${APACHE_LOG_DIR}/access-vhostX.log combined
For each virtual host create an awstats config file:
# mkdir /etc/awstats # cd /etc/awstats # cp /usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf awstats.vhostX.conf
Edit the required parameters in “/etc/awstats/awstats.vhostX.conf”:
LogFile="/var/log/apache2/access-vhostX.log" LogType=W LogFormat=1 SiteDomain="www.somedom.com" DirData="/var/lib/awstats" DirCgi="/awstats" DirIcons="/awstatsicons"
For each virtual host build the statistics database file.
Create the base directory to hold the awstats databases:
# mkdir /var/lib/awstats
Awstats comes with a tool to orderly process old log files: “logresolvemerge”. Awstats can read the resulting data via a pipe construct. 1)
Modify the awstat config file to read all access files:
# Use logresolvemerge.pl for first time setup. # LogFile="/var/log/apache2/access-vhostX.log" LogFile="/usr/local/awstats/tools/logresolvemerge.pl /var/log/apache2/access-vhostX.log* |"
Create the database for vhostX:
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=vhostX -update Create/Update database for config "/etc/awstats/awstats.vhostX.conf" by AWStats version 7.7 (build 20180105) From data in log file "/var/log/apache2/access-vhostX.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: 58 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 58 new qualified records.
After successfully creating the database restore the awstat config file for normal operation:
# Use logresolvemerge.pl for first time setup. LogFile="/var/log/apache2/access-vhostX.log" # LogFile="/usr/local/awstats/tools/logresolvemerge.pl /var/log/apache2/access-vhostX.log* |"
(Awstats FAQ)
In order to prevent losing data we need to update the awstats data files before rotating the Apache2 access logfiles.
Create directory “httpd-prerotate”:
# cd /etc/logrotate.d # mkdir httpd-prerotate # cd httpd-prerotate/
Create prerotate script “awstats-update-all”:
#!/bin/bash test -x /usr/local/awstats/tools/awstats_updateall.pl && nice /usr/local/awstats/tools/awstats_updateall.pl now >/dev/null
Make the new script executable:
# chmod +x 10-awstats.scr
Add a new crontab file “awstats” in /etc/cron.d/
# awstats crontab file # min hour daymonth month dayweek user commandline */10 * * * * root test -x /usr/local/awstats/tools/awstats_updateall.pl && nice /usr/local/awstats/tools/awstats_updateall.pl now >/dev/null
(Awstats: Contribs, plugins and resources; More info: awstats vhost config file)
Install Perl Geo::IPfree
# apt-get install libgeo-ipfree-perl
Enable “geoipfree” plugin in awstats vhost config file(s):
LoadPlugin="geoipfree"
Not tested.
By default awstats strips the querystring of the URLs. However this behaviour is inappropriate when examining a webservice which uses a querystring to identify each page. E.g. by default awstats will count all pages of a Dokuwiki as one page: /dokuwiki/doku.php
Enabling Querystring reading will solve this:
URLWithQuery=1
Limit the examination to these parameters (e.g. “id=”):
URLWithQueryWithOnlyFollowingParameters="id"
Awstats has two reporting facilities:
# cd /etc/apache2 # a2enmod cgi
The awstats cgi configuration can be configured within each Apache2 virtual host configuration or in a general Apache2 section for all hosts.
In this How-to we configure awstats cgi in a general “conf-available” section.
# cd /etc/apache2/conf-available
Create a new file “serve-awstats.conf”:
<IfModule mod_alias.c> <IfModule mod_cgi.c> Define ENABLE_USR_LIB_CGI_BIN </IfModule> <IfModule mod_cgid.c> Define ENABLE_USR_LIB_CGI_BIN </IfModule> <IfDefine ENABLE_USR_LIB_CGI_BIN> # Directives to allow use of AWStats as a CGI Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/" Alias /awstatscss "/usr/local/awstats/wwwroot/css/" Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/" ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/" <Directory "/usr/local/awstats"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Require all granted </Directory> </IfDefine> </IfModule>
Enable the new configuration file:
# a2enconf serve-awstats
Test the new Apache2 configuration:
# apache2ctl configtest Syntax OK
Now restart Apache2:
# systemctl restart apache2
See documentation: https://www.awstats.org/docs/awstats_setup.html#READ
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -help
Copyright © 2020 Tux4u.be - Author: Marjan Waldorp; awstats-install.md 2020-02-29