Time has come to create some statistics for your web sites. Webalizer is commonly used for this but development on Webalizer stopped several years ago and it lacks updates to recognize recent browsers and other vital things. This guide will use AWStats instead.
Install it form ports as usual. Just leave the default values on the options page.
# cd /usr/ports/www/awstats # make # make install clean
You will also need GeoIP.
# cd /usr/ports/net/p5-GeoIP-PurePerl # make # make install clean # mkdir /usr/local/share/GeoIP # cd /usr/local/share/GeoIP # wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz # gunzip GeoIP.dat.gz
AWStats will install itself in /usr/local/www/awstats which is inside the default path of your Apache installation. The output from the installation suggests a few additions to your Apache configuration. Those additions will create a global alias to this folder meaning that any of your virtual hosts will use this copy of AWStats simply by adding /awstats to the url. No need to maintain a separate copy for each host. Open /usr/local/etc/apache22/httpd.conf in your editor and add the following lines at the bottom but before the last Include line.
# # Directives to allow use of AWStats as a CGI # Alias /awstatsclasses "/usr/local/www/awstats/classes/" Alias /awstatscss "/usr/local/www/awstats/css/" Alias /awstatsicons "/usr/local/www/awstats/icons/" ScriptAlias /awstats/ "/usr/local/www/awstats/cgi-bin/" # # This is to permit URL access to scripts/files in AWStats directory. # <Directory "/usr/local/www/awstats/"> Options None AllowOverride None Order allow,deny Allow from all </Directory>
# /usr/local/etc/rc.d/apache22 restart
You need a config file for each of the virtual hosts you want to gather statistics for and I will guide you through the creation of the config file for http://pp.dyndns.biz/ in this tutorial. AWStat's config files must be located in /usr/local/www/awstats/cgi-bin and they have to be named awstats.your.vhost.domain.conf. There's a template included so start by making a copy of it and open the copy in your editor.
# cp /usr/local/www/awstats/cgi-bin/awstats.model.conf /usr/local/www/awstats/cgi-bin/awstats.pp.dyndns.biz.conf # ee /usr/local/www/awstats/cgi-bin/awstats.pp.dyndns.biz.conf
The first thing to tell AWStats is where to find the log file for this domain. In your setup you don't have a single log file, but one for each month because you configured log rotating if you followed the guide correctly. Because of this you need to merge them and AWStats include a tool to help you do that and an example is shown in the template. Find the following line:
Change it to:
LogFile="../tools/logresolvemerge.pl /usr/home/myweb/public_html/pp.dyndns.biz/logs/httpd-access.*.www.log |"
This will catch every logfile belonging to http://pp.dyndns.biz/ regardless of the date in the filename. Don't forget the pipe sign at the end.
Find and change the following options. Don't forget to remove the comment on the GeoIP line.
SiteDomain="" -> SiteDomain="pp.dyndns.biz" HostAliases="localhost 127.0.0.1 REGEX[myserver\.com$]" -> HostAliases="pp.dyndns.biz" DNSLookup=2 -> DNSLookup=0 AllowFullYearView=2 -> AllowFullYearView=3 LevelForWormsDetection=0 -> LevelForWormsDetection=2 ShowWormsStats=0 -> ShowWormsStats=HBL ShowScreenSizeStats=0 -> ShowScreenSizeStats=1 #LoadPlugin="geoip GEOIP_STANDARD /pathto/GeoIP.dat" -> LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
Now you must run awstats.pl manually the first time to look for any errors. Note that the -config parameter only contains your domain name and not the full name of the config file.
# cd /usr/local/www/awstats/cgi-bin # perl awstats.pl -config=pp.dyndns.biz -update
If everything looks fine you can add the following line to crontab.
@hourly cd /usr/local/www/awstats/cgi-bin ; perl awstats.pl -config=pp.dyndns.biz -update >/dev/null
If you have more sites to run statistics for, you'll just create another config file and add that update command to the end of the crontab entry above so they won't all run simultaneously. To watch the statistics, simply browse to the script and AWStats will automatically chose the correct config file by checking the url requested - http://pp.dyndns.biz/awstats/awstats.pl