|
|
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:
- 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..
- Run RPM or tar to install AWStats.
- Locate where awstats is installed. On my system,
it us /usr/share/awstats.
- $TOMCAT_HOME should point to where Tomcat is installed.
- cp -pr /usr/share/awstats/wwwroot/cgi-bin $TOMCAT_HOME/webapps/ROOT/WEB-INF/cgi
- cd $TOMCAT_HOME/webapps/ROOT/WEB-INF/cgi
- Edit the first line awstats.pl to point to your perl intallation, e.g.,
#!/usr/local/bin/perl
- cp -f awstats.pl awstats.cgi
- cd to the directory containing awstats/tools, e.g.,
cd /usr/share/awstats/tools
- perl awstats_configure.pl
- awstats_configure.pl will ask some questions. When it asks
for the type of log file, specify a combined logfile format.
- 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.
- The generated conf file is found at /etc/awstats/awstats.mydomain.com.conf
- cd $TOMCAT_HOME/webapps/ROOT/
- cp -pr /usr/share/awstats/wwwroot/icon awstatsicons
- cd WEB-INF
- cp /etc/awstats/awstats.www.mydomain.com.conf .
- 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]"
- cd $TOMCAT_HOME/conf
- 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"/>
- Be sure to change pattern="common" to pattern="combined" in the valve above.
- 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>
- cd $TOMCAT_HOME/lib
- mv -f servlets-cgi.renametojar servlets-cgi.jar"
- mv -f servlets-ssi.renametojar servlets-ssi.jar
- Restart Tomcat
- 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
- Create a cron job to run AWStats every night using the above script.
NOTE: AWStats only reads logs from the previous day.
0 1 * * * /root/instructions/awstats_cron.sh 2>&1 >> /root/awstats_cron.log
- Bring up AWStats in your web browser, e.g.,
http://www.mydomain.com/cgi-bin/awstats.cgi
|
|