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:
- Unique hits
- Time of visit
- Amount of pages served
- Duration of stay
- Download count
- Traffic produced
- 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:
- XAMPP (or standalone Apache installation)
- AWStats
- Perl
- Apache Log File(s)
- 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:
- Extract AWStats to a temporary location, e.g. /tmp/awstats-7.0
- 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>
- 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
- 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/
- Copy /tmp/awstats-7.0/wwwroot/icon to the icons Alias folder specified in vhost config file, e.g. C:/awstats/icon/
- 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
- 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.
Leave a Reply