This month, I’ve had a chance to play around with AWStats and Sitecore. The main purpose is to provide website statistics of the past days / weeks / years with a friendly user interface to the site admin / web master.
How about Sitecore Analytics? Sitecore License has had NO xDB enabled so they’ve not used Sitecore Analytics since day 1. Of course, the good replacement – Google Analytics – just has been integrated recently.
Assumptions
- single Sitecore instance
- is hosted on IIS / Windows web server
- open source and can run on Windows
- depends on IIS log files
Step by step set-up guide of AWStats
- install Perl if NOT YET
- note: personally, I wanted to eat Strawberry
- navigate to AWStats Download and then download AWStats version 7.7 (the latest stable version at this moment)
- unzip and then copy / paste wwwroot folder to our Sitecore website folder + rename it to awstats for a better practice
- Note: we can add a virtual directory to IIS site and name it awstats instead of copying wwwroot folder to our Sitecore website folder
- let’s configure AWStats for Microsoft’s IIS server by following this instruction
- access [Sitecore website folder]\awstats\cgi-bin
- create a configuration file by clone awstats.model.conf and rename it to awstats.viethoang.conf
- next step is to edit awstats.viethoang.conf to match our specific environment
- change the LogFile value to the full path of our web server log file, for instance: “C:\inetpub\logs\LogFiles\W3SVC39\u_ex200319.log”
- Note 1: we can get the correct folder based on the following info
- Note 2: there are many log files so we should merge them all into one single file, otherwise we will have to process one by one to build statistics database
- change the LogFormat to 2
- change the DirIcons parameter to reflect relative path of icon directory, in this case it should be /awstats/icon
- set the SiteDomain parameter to the main domain name or the intranet web server name used to reach the web site being analyzed
- okay it should be enough, let’s process the logs now by following this instruction
- open Command Prompt and change directory to [Sitecore website folder]\awstats\cgi-bin
- run perl awstats.pl -config=viethoang
- hopefully, you would see something like this
- so far so good, let’s view our statistics from a browser
- navigate to [Sitecore host name]/awstats/cgi-bin/awstats.pl?config=viethoang, you may get the following error HTTP Error 404.3 – Not Found
- as our IIS doesn’t know anything about Perl so we need to add the following Script Map via Handler Mappings feature of IIS
- Note: you may get the following error HTTP Error 502.2 – Bad Gateway as you miss “%s” %s in Executable field above
- hopefully, you would see something like this
How to update the statistics
We should open [Sitecore website folder]\awstats\cgi-bin\awstats.viethoang.conf and then set the LogFile value to name pattern for the log files are created by IIS, for instance “C:\inetpub\logs\LogFiles\W3SVC39\u_ex%YY%MM%DD-24.log” so AWStats can process the latest + completed log file (normally, it’s the log file of yesterday)
Generally, we have 2 ways to keep the statistics updated:
- manual update via browser
- set the AllowToUpdateStatsFromBrowser parameter to 1
- navigate to [Sitecore host name]/awstats/cgi-bin/awstats.pl?config=viethoang you would see Update now link button
- Note: you may get the following error Permission denied after clicking Update now button
- in this case, just ensure granting permission to IUSR user to access “C:\inetpub\logs\LogFiles\W3SVC39″ folder
- create a Windows task scheduler for updating the statistics daily + automatically
How to secure AWStats
We can follow this instruction as medium secured policy so we should open [Sitecore website folder]\awstats\cgi-bin\awstats.viethoang.conf and then edit it:
- set AllowAccessFromWebToAuthenticatedUsersOnly to 1
- update ErrorMessages as well so we will have a more secured and friendly error message
- create a list of authorized users in the AllowAccessFromWebToFollowingAuthenticatedUsers parameter so they can access AWStats
Notes
- ensure that the bandwidth statistics is available by checking Byte Sent and Byte Received logging fields via Logging feature of IIS (note: they might be not checked by default)
- if we want to have our statistics to be indexed, set MetaRobot to 1
- if end users must go through proxies / load balancers before accessing the web application, the client IP address field (c-ip by default) in IIS log will show the IP address of network device instead of client’s IP address. So we should use X-Forwarded-For request header to log the IP address of the client, e.g we will add a new field manually to IIS log (Ex: X-Forwarded-For) and then update LogFormat of AWStats to map that new field correctly
- assume that the fields of our IIS log will be like this
- we will update LogFormat in our AWStats config file to this
The references
- https://www.damirscorner.com/blog/posts/20150105-HowToConfigureAwstatsForWindowsAndIis.html
- https://devio.wordpress.com/2017/03/07/installing-awstats-on-windows-server-2012/
- https://www.howtogeek.com/50526/setting-up-awstats-on-windows-server-and-iis/
Happy Sitecore Playing!
To let run AWStats on IIS10, you need to use the Script map without “… like this> C:\Perl\perl\bin\perl.exe %s %s in Executable field. (no double quotes).
LikeLiked by 1 person
Thanks, probably as I used Strawberry instead of Perl so there is a slight difference 😁
LikeLike