You are here: Home / Debian GNU/Linux / Web applications / Statistics / Install AWStats Web analytics tool on Debian

Install AWStats Web analytics tool on Debian

by Pierre-Yves Landuré last modified Oct 04, 2017 12:27

AWStats (for Advanced Web statistics) is a powerful log file analysis tool. It is able to process HTTP, FTP and SMTP servers logs. Its design is simple and easy to understand. This howto help to install it on Debian.

This howto is tested on :

  • Debian 5.0 Lenny
  • Debian 6.0 Squeeze

Prerequisites

This howto needs a Apache 2 HTTP server with the script a2tools available in the howto Install Apache 2 on Debian.

Parameters

Provide the domain name where will be available the software :

DOMAIN="stats.domain.com"

Installation

Install the software, a password generator and the plug-ins dependencies :

command apt-get install awstats apg \
libgeo-ipfree-perl libnet-ip-perl \
libnet-dns-perl liburi-perl apache2-utils

Create a system user for the software :

command adduser --system --group --shell "/bin/sh" \
    --no-create-home --home "/var/lib/awstats" "awstats"
command adduser "awstats" "adm"

Give ownership of the software files to this user :

if [ -e "/var/lib/awstats" ]; then
  command chown awstats:www-data "/var/lib/awstats"
  command chown awstats:awstats "/var/lib/awstats/"*
fi
if [ -e "/var/cache/awstats" ]; then
  command chown awstats:www-data "/var/cache/awstats"
  command chown awstats:awstats "/var/cache/awstats/"*
fi

Replace the default cron configuration by a version that can use more than one configuration file :

command echo "# Awstats all sites update :
*/10 * * * * awstats [ -x '/usr/lib/cgi-bin/awstats.pl' -a -d '/etc/awstats' ] && command find '/etc/awstats' -type f -name 'awstats.*.conf' | command sed -e 's/.*awstats\.\(.*\)\.conf/\1/' | command xargs -ICONF /usr/lib/cgi-bin/awstats.pl -config=CONF -update

# Generate static reports:
#10 03 * * * awstats [ -x '/usr/share/awstats/tools/buildstatic.sh' ] && /usr/share/awstats/tools/buildstatic.sh" \
  > /etc/cron.d/awstats
/etc/init.d/cron reload

Setup the software to use the "combined" version of Apache 2 logs :

command sed -i -e 's/^LogFormat.*=.*/LogFormat=1/g' "/etc/awstats/awstats.conf"

Allow the complete year view when using browser :

command sed -i -e 's/^AllowFullYearView.*=.*/AllowFullYearView=3/g' "/etc/awstats/awstats.conf"

Copy the default configuration file in order to have a safe template :

command mv "/etc/awstats/awstats.conf" "/etc/awstats/awstats.conf.template"

Enable for all sites the interesting plug-ins of the software :

command echo 'LoadPlugin="tooltips"
LoadPlugin="decodeutfkeys"
LoadPlugin="ipv6"
LoadPlugin="geoipfree"' \
    >> "/etc/awstats/awstats.conf.local"

User management initialization

Create the folder storing the passwords file :

command mkdir --parent "/etc/apache2/passwords"

Create a password for the admin account, allowed to view every site statistics :

AWSTATS_PWD="$(command apg -q -a 0 -n 1 -M NCL)"

Create the passwords file and the admin account :

command htpasswd -cb "/etc/apache2/passwords/awstats-users.pwd" "admin" "${AWSTATS_PWD}"

Display the password assigned to the administration account of the software. Remember it :

command echo "The password of the 'admin' user is '${AWSTATS_PWD}'."

This account allow to view the statistics of every site statistics managed by AWStats.

Apache 2 configuration

Enable Apache 2 mod rewrite :

command a2enmod rewrite

Download the AWStats VirtualHost template :

AWSTATS_CONFIG="$(command wget "https://raw.github.com/biapy/howto.biapy.com/master/apache2/awstats/awstats-virtual-host.template" \
    --quiet --no-check-certificate --output-document=-)"

Create the statistics web application Apache 2 setup with a2tools :

command a2tools --template=custom "${DOMAIN}" "${AWSTATS_CONFIG}"

By default, the VirtualHost template used only allow the "admin" user to view the sites statistics. If you edit the file "/etc/apache2/sites-available/http-DOMAIN", you can allow access without login for some IP addresses.

Administration script installation

Install the AWStats administration script :

command wget "https://raw.github.com/biapy/howto.biapy.com/master/apache2/awstats/awstats-tools" \
--quiet --no-check-certificate --output-document="/usr/bin/awstats-tool"
command chmod +x "/usr/bin/awstats-tool"

The use of this script for the chosen domain is given by :

echo "* awstats-tool ${DOMAIN} add-site www.example.com
Add the site www.example.com to the statistics generated by AWStats.

* awstats-tool ${DOMAIN} add-site-user www.example.com jdoe
Create the 'jdoe' user, and allow him to access the www.example.com site statistics.

The statistics for the www.example.com site are available on this URL : http://${DOMAIN}/www.example.com/"

Backups

Backup the installation with Backup Manager (see Install and setup Backup Manager on Debian) :

command backup-manager-tools add "/etc/awstats"
command backup-manager-tools add "/var/lib/awstats"

Thanks

  • Thanks to AWStats developers.
  • Thanks to the author of "Rewrite for Awstats" in the htaccess Elite forum for showing me the way.
  • Thanks to Qtax on irc.freenode.net#regex.