Setup AWStats in XAMPP for Offline Apache Log File Analysis

AWStats Logo

Recently I was asked to do Apache log file analysis for a customer portal. Up until then no log file analysis has been done for this particular site and only raw Apache log data was available. Thus, I needed to find a way to be able to do offline Apache log file analysis to satisfy to following demands:

  1. Unique hits
  2. Time of visit
  3. Amount of pages served
  4. Duration of stay
  5. Download count
  6. Traffic produced
  7. Geographic Distribution

The easiest way to accomplish this task would be do feed the log files to an existing analysis tool, such as AWStats (or Webalizer in case you don’t like AWStats which represents a viable alternative).

Furthermore, with reusability in mind I wanted to accomplish a setup that could be easily re-used for analyzing log files from other sites later on as well. Consequently, I decided to setup AWStats in conjunction with XAMPP based on a virtual host environment.

This article explains the steps required to setup AWStats in XAMPP, as well as how to actually do log analysis based on different sets of log files.

The Requirements

Please bear in mind that some requirements need to be met in order to run this setup:

  1. XAMPP (or standalone Apache installation)
  2. AWStats
  3. Perl
  4. Apache Log File(s)
  5. Optional: Apache virtual host configuration

One of the benefits of using XAMPP instead of a plain Apache HTTP server is that it already contains a working Perl installation, which comes in handy if you are looking for a jump-start.

The Setup

First, you need to setup XAMPP. For information on how to do is please refer to the official setup guide on Windows. Then, you need to install and configure AWStats to be used in your XAMPP environment. In order for AWStats to get to work you also need to setup Perl. Fortunately, XAMPP already includes Perl so you won’t need to install it yourself. In case you decide against XAMPP there are a lot of tutorials explaining the steps to get Perl running with Apache.

So basically, after installing XAMPP everything boils down to setting up AWStats to be used in combination with XAMPP. As there are numerous ways to do so, the following merely represents one possible working solution:

  1. Extract AWStats to a temporary location, e.g. /tmp/awstats-7.0
  2. Create a vhost entry with the following settings:
    <VirtualHost *:80>
      ServerName awstats.local
      DocumentRoot "C:/awstats"
    	
      ScriptAlias /cgi-bin/ "C:/awstats/cgi-bin/"
      Alias /icons "C:/awstats/icon/"
    
      <Directory "C:/awstats">
        AllowOverride All
        Allow from All
      </Directory>
    </VirtualHost>
    
  3. For the vhost entry above to work you need to edit your hosts file, e.g. in Windows add 127.0.0.1 awstats.local to C:\Windows\System32\drivers\etc\hosts
  4. Copy contents of /tmp/awstats-7.0/wwwroot/cgi-bin to the cgi-bin ScriptAlias folder specified in vhost config file, e.g. C:/awstats/cgi-bin/
  5. Copy /tmp/awstats-7.0/wwwroot/icon to the icons Alias folder specified in vhost config file, e.g. C:/awstats/icon/
  6. Edit the path to the Perl install in cgi-bin/awstats.pl, e.g. on Windows instead of #!/usr/bin/perl use #!c:\xampp\perl\bin\perl.exe when using XAMPP
  7. For each site to analyze create an AWStats model file using awstats.model.conf as reference (see cgi-bin folder), e.g. awstats.my-site.conf and be sure to set the following options:
    • LogFile, e.g. “C:/awstats/cgi-bin/logs/access.my-site.log”
    • DirData, e.g. “C:/awstats_data” (make sure this folder exists before running AWStats
    • SiteDomain, this must conform with the domain used in your log file, e.g. “my-site.com”
    • DirIcons, specifies to path to the icons Alias previously set, i.e. “/icons”

That’s should suffice for AWStats to run. Now we are able to generate the analytics data by issuing the following command:

perl awstats.pl -config=my-site -update

Finally, in order to view the nicely formatted output produced by AWStats we can run the web-view:

http://awstats.local/cgi-bin/awstats.pl?config=my-site

Analyzing Multiple Sites

Based on this setup you can easily analyze further log files from other sites by creating separate model files (e.g. awstats.my-other-site.conf) and placing them in the cgi-bin folder of the vhost directory and finnally running the command to generate analysis data.

That’s all it takes to setup AWStats in combination with XAMPP to do offline Apache log file analysis for multiple sites without further configuration.

Comments

8 responses to “Setup AWStats in XAMPP for Offline Apache Log File Analysis”

  1. huaz Avatar
    huaz

    Thank you 😛

    1. matthias.kerstner Avatar

      Hey huaz,
      I’m glad this was useful for you. Cheers

  2. milan Avatar
    milan

    Where am I supposed to issue command?

    1. matthias.kerstner Avatar

      Hi milan,
      you need to run the command from your command line (Windows) or shell (*nix systems). Either specify the full path to the perl executable or make sure perl is in your path. Hope that helps. Cheers

  3. milan Avatar
    milan

    You are a life saver 🙂 I lost a lot of time searching for this article because everyone was explaining how to do it on Linux. Finally 😀 😀 😀 !!!

    1. matthias.kerstner Avatar

      Hey, you’re most certainly welcome 🙂 Cheers

  4. jay Avatar
    jay

    Hi Matthias,

    I followed the steps and was able to analyse the access.log file OK. But when I try and see the awstats formatted output. My IE8 browser just says “Internet Explorer cannot display the webpage”
    Does it need a higher version of IE?

    Any ideas?

    Thx

  5. Paresh Chauhan Avatar

    Hi,

    I have referred above steps and installed awstats with XAMPP on Windows-10.

    Unfortunately, I could not get data on my URL. I received output script awstats.pl on my URL.

    Can you please suggest me which steps I miss?

    Regards,
    Paresh Chauhan

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.