Back to the Konsensys

Back to Tips
How to set up AWStats on the Apache Tomcat Webserver (Running on Linux)
by
George Van Treeck

AWStats is very popular and free tool for displaying statistics about your web site, such as the number of visitors, number of return visitors, what search keywords were used to get to your site, which pages are viewed most often, etc. Unfortunately, I was not able to find good instructions for installing on Tomcat on Linux. So, I decided to write some instructions:

  1. Download AWStats onto your Linux system from SourceForge (download links near the bottom of the page). Select the RPM version if installing on RedHat. Select the tar.gz version for Debian, Unbunto, etc..
  2. Run RPM or tar to install AWStats.
  3. Locate where awstats is installed. On my system, it us /usr/share/awstats.
  4. $TOMCAT_HOME should point to where Tomcat is installed.
  5. cp -pr /usr/share/awstats/wwwroot/cgi-bin $TOMCAT_HOME/webapps/ROOT/WEB-INF/cgi
  6. cd $TOMCAT_HOME/webapps/ROOT/WEB-INF/cgi
  7. Edit the first line awstats.pl to point to your perl intallation, e.g., #!/usr/local/bin/perl
  8. cp -f awstats.pl awstats.cgi
  9. cd to the directory containing awstats/tools, e.g., cd /usr/share/awstats/tools
  10. perl awstats_configure.pl
  11. awstats_configure.pl will ask some questions. When it asks for the type of log file, specify a combined logfile format.
  12. When asked for the name of the configuration profile, specify either the name of your server or your domain name, e.g., www.mydomain.com.
  13. The generated conf file is found at /etc/awstats/awstats.mydomain.com.conf
  14. cd $TOMCAT_HOME/webapps/ROOT/
  15. cp -pr /usr/share/awstats/wwwroot/icon awstatsicons
  16. cd WEB-INF
  17. cp /etc/awstats/awstats.www.mydomain.com.conf .
  18. Edit the conf file to specify the following (change the paths and names to what is appropriate for your envirionment:
    LogFile="/usr/local/tomcat/logs/localhost_access_log.%YYYY-24-%MM-24-%DD-24.txt"
    ...
    LogType=W
    ...
    LogFormat=1
    ...
    LogSeparator=" "
    ...
    siteDomain=www.mydomain.com
    ...
    HostAliases="www.mydomain.com localhost 127.0.0.1 REGEX[www\.mydomain\.(com|net|org)]"
    ...
    SkipHosts="127.0.0.1 your_IP_addresses"
    ...
    SkipFiles="robots.txt$ favicon.ico$ Alive$ REGEX[^\/images] REGEX[^\/awstatsicons] REGEX[^\/cgi-bin]"
    
  19. cd $TOMCAT_HOME/conf
  20. Edit your server.xml to uncomment the AccessLogValve. If you have installed he Apache binaries for Tomcat, then the valve will look as follows:
    <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt" pattern="combined" resolveHosts="false"/>
    
  21. Be sure to change pattern="common" to pattern="combined" in the valve above.
  22. Edit your server.xml to enable CGI file execution by inserting the following:
    Fragment 1
    
    <servlet>
       <servlet-name>cgi</servlet-name>
       <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
       <init-param>
          <param-name>clientInputTimeout</param-name>
          <param-value>100</param-value>
       </init-param>
       <init-param>
          <param-name>debug</param-name>
          <param-value>6</param-value>
       </init-param>
       <init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi</param-value>
       </init-param>
       <load-on-startup>5</load-on-startup>
    </servlet>
    
    Fragment 2
    <!-- The mapping for the CGI Gateway servlet -->
    <servlet-mapping>
       <servlet-name>cgi</servlet-name>
       <url-pattern>/cgi-bin/*</url-pattern>
    </servlet-mapping>
    
  23. cd $TOMCAT_HOME/lib
  24. mv -f servlets-cgi.renametojar servlets-cgi.jar"
  25. mv -f servlets-ssi.renametojar servlets-ssi.jar
  26. Restart Tomcat
  27. Create a bash script, awstats_cron.sh:
    #!/bin/sh
    cd /usr/local/tomcat/webapps/ROOT/WEB-INF/cgi
    ./awstats.pl -config=www.mydomain.com -update
    
  28. Create a cron job to run AWStats every night using the above script. NOTE: AWStats only reads logs from the previous day.
  29. 0 1 * * * /root/instructions/awstats_cron.sh 2>&1 >> /root/awstats_cron.log
    
  30. Bring up AWStats in your web browser, e.g., http://www.mydomain.com/cgi-bin/awstats.cgi

Copyright (C) 2010 George Van Treeck. All rights reserved.