SEARCH

How-To Geek

Setting up AWStats on Windows Server and IIS

When it comes to gathering statistics on web sites, you can never have enough. While one of the most popular method for tracking statistics is through services such as Google Analytics, log file analysis remains a reliable way to track your visitors as they are immune to script blockers. A widely used tool for log file analysis is the open source tool, AWStats.

Before setting up AWStats, you will need to make sure Perl installed on your Windows Server 2003/IIS 6 or Windows Server 2008/IIS 7 machine.

Configuring Web Site Logging

In order to capture the data AWStats tracks, your sites must log the following fields:

  • date
  • time
  • c-ip
  • cs-username
  • cs-method
  • cs-uri-stem
  • sc-status
  • sc-bytes
  • cs-version
  • cs(User-Agent)
  • cs(Referer)

IIS 6 Setup

To configure logging in IIS 6, open IIS Manager and right click on the Web Sites folder and select Properties.

image

On the Web Site tab, click the Properties button in the Enable logging section.

image

In the Logging Properties, configure the schedule to be daily with local time used for file naming and rollover.

image

On the Advanced tab, configure the required fields to be logged.

image

image

Apply your changes.

IIS 7 Setup

To configure logging in IIS 7, open IIS Manager and select Logging from the server configuration options.

image

In the Logging configuration, set up a single log file per site which rolls over daily using the local time for file naming.

image

Click the Select Fields button and check the boxes next to the required fields.

image

Apply your changes.

Setting Up AWStats

Download the AWStats zip package from Sourceforge. Create a folder called ‘awstats’ in your ‘C:inetpubwwwroot’ folder and extract the following files from the downloaded zip file to this folder:

  • /wwwroot/icon
  • /wwwroot/cgi-bin/lang
  • /wwwroot/cgi-bin/lib
  • /wwwroot/cgi-bin/plugins
  • /wwwroot/cgi-bin/awredir.pl
  • /wwwroot/cgi-bin/awstats.model.conf
  • /wwwroot/cgi-bin/awstats.pl

image

Once the files are extracted, copy the “awstats.model.conf” file to a file named “awstats.domain.com.conf” (where domain.com is the site to track), open it in Notepad and configure the options as needed.

The first thing you will need to configure is the log file location, which by default is located here:

  • Server 2003: C:WINDOWSsystem32LogFilesW3SVC[IIS_ID]
  • Server 2008: C:inetpublogsLogFilesW3SVC[IIS_ID]

You can find the IIS ID by looking at the master site listing in IIS Manager and noting the value in the ID column next to the respective site.

image

Set the options in the configuration file. This file has a very good explanation of what each option does, so take a few minutes to review them. Here are a few settings of interest according to the setup above:

  • LogFile=”C:inetpublogsLogFilesW3SVC1u_ex%YY-24%MM-24%DD-24.log” (Server 2008/IIS 7 where the stats are calculated daily)
  • LogFile=”C:WINDOWSsystem32LogFilesW3SVC1ex%YY-4%MM-4%DD-4.log” (Server 2003/IIS 6 where the stats are calculated every 4 hours to be updated throughout the day)
  • LogFormat=”date time cs-method cs-uri-stem cs-username c-ip cs-version cs(User-Agent) cs(Referer) sc-status sc-bytes”
  • SiteDomain=”domain.com”
  • HostAliases=”www.domain.com 11.22.33.44″ (any other URL’s which point to your site)
  • DirIcons=”icon”
  • DefaultFile=”index.php index.html”

Once you have saved your configuration file, run the AWStats Perl Script to compile the stats data. The command looks like this:

C:inetpubwwwrootawstats>C:Perlbinperl.exe awstats.pl -config=domain.com

image

The above command assumes the following (configuration used for this article):

  • The folder “C:inetpubwwwrootawstats” serves the stats through IIS.
  • Perl was installed to the “C:Perl” directory.
  • The config file is named “awstats.domain.com.conf”.

Finally, you can access the stats data through your browser. This URL is publically available for anyone to view unless you configure security via IIS. To test our configuration, just browse to:

http://localhost/awstats/awstats.pl?config=domain.com

image

Scheduling Stats Update

One of the configurations we set in the config file is the ‘LogFile’ location which defines the amount of hours to subtract from the date portions of the file. So to automate the process of compiling your stats, set up a Windows Scheduled Task which runs the command you used above to build the stats on the interval you configured.

Links

Download AWStats (zip package)

Jason Faulkner is a developer and IT professional who never has a hot cup of coffee far away. Interact with him on Google+

  • Published 07/23/10

Comments (7)

  1. Macleena

    Good Article…

  2. matt

    Hi,

    thanks for the info…how do you setup awstats if you have multiple domains using different port nos. In my case i have disabled the default domain.

    Please advise.

    Thanks,

    Matt

  3. Jason Faulkner

    Matt – The port number shouldn’t matter. All the info AWStats needs is located in the log file for the respective site.

  4. byte_slave

    Hi guys,

    Awsome article! I was wondering this setup fits an intranet scenario?

    Thanks!

    Regards,
    bs

  5. Jason Faulkner

    @byte_slave – AWStats works totally within the IIS setup. It doesn’t matter the scope of the site being served.
    In other words this will work for public, private, test (and any other) IIS sites.

  6. byte_slave

    @Jason – Thats great! Thanks a lot for your input!

  7. Stewart

    Thanks for your clear information. Incidentally, is it possible to also automate the creation of a folder for each month of the year, and to move the stats into the relevant folder at the end of each month? I need to track monthly stats more specifically than AWstats allows if I don’t copy them over monthly, and doing that is a pain.

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!