User Tools

Site Tools


Install and Configure awstats

Install procedure on Linux

Information on the project is located at

A good article about awstats can be found on:

Installing awstats

Download the latest awstats version from internet:

…and install the software on your server:

[root@eul0000907 root2]# wget
           => `awstats-6.6-1.noarch.rpm'
Connecting to||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,139,488 (1.1M) [application/x-redhat-package-manager]
100%[========================================================>] 1,139,488      6.64M/s
12:31:27 (6.64 MB/s) - `awstats-6.6-1.noarch.rpm' saved [1139488/1139488]
[root@eul0000907 root2]# rpm -i awstats-6.6-1.noarch.rpm
----- AWStats 6.6 - Laurent Destailleur -----
AWStats files have been installed in /usr/local/awstats
If first install, follow instructions in documentation
(/usr/local/awstats/docs/index.html) to setup AWStats in 3 steps:
Step 1 : Install and Setup with (or manually)
Step 2 : Build/Update Statistics with
Step 3 : Read Statistics

Set up directories to store data

Build a directory structure that holds your log-files and awstats databases:


The /logs Directory is not nedded if you reference on the /var/log/httpd files directly.

Configure awstats

Copy model config file located in /etc/awstats/awstats.model.conf Adapt the following pramaters:


Apache configuration

Make shure the cgi Module is loaded, for that the following line in httpd.conf must be present:

LoadModule cgi_module modules/

Example of the Virtual Host configuration:

<VirtualHost *:80>
    DocumentRoot "/usr/local/awstats/wwwroot"
    # AWStats configuration
    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/"
    # This is to permit URL access to scripts/files in AWStats directory.
    <Directory "/usr/local/awstats/wwwroot">
      Options None
      AllowOverride None
      Order allow,deny
      Allow from all

Create Databases

Before we can build the statistic database, we have to copy the server logs we want to analyze.


cp /var/log/httpd/ /home/www/sta/stats/

Next we can execute the awstats script which builds the database:

[root@eul0000907 cgi-bin]# perl /usr/local/awstats/wwwroot/cgi-bin/ -config=example -update
Create/Update database for config "/etc/awstats/awstats.example.conf" by AWStats version 6.6 (build 1.887)
From data in log file "/home/www/sta/stats/"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 3563)
Jumped lines in file: 3563
 Found 3563 already parsed records.
Parsed lines in file: 0
 Found 0 dropped records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 0 new qualified records.
[root@eul0000907 cgi-bin]#

Add authentication

Adapt the config file of awstats to allow only specific authenticated users

# The following two parameters allow you to protect a config file from being
# read by AWStats when called from a browser if web user has not been
# authenticated. Your AWStats program must be in a web protected "realm" (With
# Apache, you can use .htaccess files to do so. With other web servers, see
# your server setup manual).
# Change : Effective immediatly
# Possible values: 0 or 1
# Default: 0
# This parameter gives the list of all authorized authenticated users to view
# statistics for this domain/config file. This parameter is used only if
# AllowAccessFromWebToAuthenticatedUsersOnly is set to 1.
# Change : Effective immediatly
# Example: "user1 user2"
# Example: "__REMOTE_USER__"
# Default: ""

Insert the following into the apache virtual host config:

 <Directory "/usr/local/awstats/wwwroot">
      Options None
      AllowOverride None
      Order allow,deny
      Allow from
      Allow from
      Allow from
      AuthType Basic
      AuthName "eul0000907 stats"
      AuthUserFile "/home/www/sta/stats/stats.auth"
      require valid-user

Add the htaccess file:

htpasswd -cm stats.auth telematic

Run awstats regularly

It's a good idea to adapt the logrotate script such as a minimum of logs gets lost if the log file changes.

Example config for logrotate:

cat /etc/logrotate.d/httpd
/var/log/httpd/*log {
    # start awstats config
        perl /usr/local/awstats/wwwroot/cgi-bin/ -update -config=example
    # end awstats config
        /bin/kill -HUP `cat /var/run/ 2>/dev/null` 2> /dev/null || true

Add a task under crontab (here in /etc/cron.hourly)

perl /usr/local/awstats/wwwroot/cgi-bin/ -config=example -update >/dev/null

Install procedure on Windows (IIS 6.0)

  • Install awstats (.exe installer)
  • Configure IIS
    • Create Host for stats
    • Copy awstats dir to web root
    • for Perl: “Home Directory” ⇒ “Application Settings” ⇒ “Connfiguration…” ⇒ “Add..” ⇒ .pl / perlis.dll

  • “Web Service Extensions”: Perl / perlis.dll / Allowed

  • change log format:
    1. Date (date)
    2. Time (time)
    3. Client IP Address (c-ip)
    4. User Name (cs-username)
    5. Method (cs-method)
    6. URI Stem (cs-uri-stem)
    7. Protocol Status (sc-status)
    8. Bytes Received (sc-bytes)
    9. Protocol Version (cs-version)
    10. User Agent (cs(User-Agent))
    11. Referrer (cs(Referrer))

  • create awstats config file for your host (here in cgi-bin directory):
LogFormat = "date time cs-method cs-uri-stem cs-username c-ip cs-version cs(User-Agent) cs(Referer) sc-status sc-bytes"
  • Create database:
    • go to web root where is found
D:\stats\cgi-bin>perl -update
  • Create a task to run this batch file reguarly:
rem batch file to update awstats every hour by scheduled task
rem Nik Wolfgramm 01.11.2007
@echo off
cd D:\stats\cgi-bin\
perl -update

Batch script for Load Balanced servers

rem @echo off
rem batch file to get log files from 2 server nodes, merge them 
rem and to update awstats every hour by scheduled task
rem Nik Wolfgramm 19.12.2007

rem set time and dates
for /f "tokens=1-4 delims=/ " %%g in ('date /t') do (
  set dd=%%g
  set mm=%%h
  set yyyy=%%i
set yy=%yyyy:~2%
set time=%time /t%
set time=%'time:~0,2'%

rem configuration section
set map_drive=s:
set log_drive1=\\\d$
set log_drive2=\\\d$
set log_folder=\log\W3SVC760071087
set loc_drive=d:\weblog
set log_file=ex%yy%%mm%%dd%

rem map the network drive of server 1
net use %map_drive% %log_drive1%

rem Copy log file of today from web server 1 
copy %map_drive%%log_folder%\%log_file%.log %loc_drive%\%log_file%-1.log.tmp /Y > %loc_drive%\1297_%mm%%dd%.txt

rem Release the network drive
net use %map_drive% /d

rem map the network drive of server 2
net use %map_drive% %log_drive2%

rem Copy log file of today from web server 2
copy %map_drive%%log_folder%\%log_file%.log %loc_drive%\%log_file%-2.log.tmp /Y > %loc_drive%\1301_%mm%%dd%.txt

rem Release the network drive
net use %map_drive% /d

rem Merge the two log files
perl "C:\Program Files\AWStats\tools\"  %loc_drive%\%log_file%-1.log.tmp  %loc_drive%\%log_file%-2.log.tmp > %loc_drive%\%log_file%.log

rem delete teporary log files
del %loc_drive%\%log_file%-1.log.tmp
del %loc_drive%\%log_file%-2.log.tmp

rem update the statistics
cd D:\stats\cgi-bin\
perl -config=eu-shop -update
cd ..
/srv/ · Last modified: 2009/08/15 19:37 (external edit)