AWstats
Views:
How to setup AWstats to show web site statistic for multiple web sites and get location information for visitors.
Contents |
Installing AWstats
First download AWstats and unpack it
# cd /usr/local/src # wget http://prdownloads.sourceforge.net/awstats/awstats-6.9.tar.gz # tar zxvf awstats-6.9.tar.gz # chown -R root:root awstats-6.9 # chmod -R u-s,g-s awstats-6.9 # cd awstats-6.9
Start making a new virtual host which will be serving up the reports
# mkdir -p /var/www/vhosts/stats.ninjafocus.net/conf # mkdir /var/www/vhosts/stats.ninjafocus.net/htdocs # mkdir /var/www/vhosts/stats.ninjafocus.net/logs # mkdir /var/www/vhosts/stats.ninjafocus.net/awstats/public # ln -s /var/www/vhosts/stats.ninjafocus.net/awstats/public /var/www/vhosts/stats.ninjafocus.net/htdocs/awstats
We're going to slightly reorganise the files that come with AWstats.
Copy the supporting assets to the "public" folder created above
# cd /usr/local/src/awstats-6.9/wwwroot # cp -rp css /var/www/vhosts/stats.ninjafocus.net/awstats/public/ # cp -rp icon /var/www/vhosts/stats.ninjafocus.net/awstats/public/ # cp -rp classes /var/www/vhosts/stats.ninjafocus.net/awstats/public/ # cp -rp js /var/www/vhosts/stats.ninjafocus.net/awstats/public/
Copy the cgi scripts over, but get rid of the configuration file
# cd /usr/local/src/awstats-6.9/wwwroot # cp -rp cgi-bin /var/www/vhosts/stats.ninjafocus.net/awstats/ # rm /var/www/vhosts/stats.ninjafocus.net/awstats/cgi-bin/awstats.model.conf
and copy the utility scripts out too
# cd /usr/local/src/awstats-6.9/tools # mkdir /usr/local/share/awstats # cp -p * /usr/local/share/awstats/
Now we need somewhere to store the configuration files.
# mkdir /usr/local/etc/awstats # cp -p cgi-bin/awstats.model.conf /usr/local/etc/awstats/
and somewhere for variable data
# mkdir /var/lib/awstats
Geo Location
For the geo-location we will need to install the MaxMind GeoIp Library and an additional perl module.
On CentOS you can install GeoIp with yum
# yum install GeoIP GeoIP-data GeoIp-devel
Installing from source is quite easy
# cd /usr/local/src # wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz # tar zxvf GeoIP-1.4.6.tar.gz # ./configure && make && make check && make install
The perl module can be installed very easily with cpan
# cpan -i Geo::IPfree # cpan -i Geo::IP # cpan -i Geo::IP::PurePerl
A copy of the GeoIp data will be in /usr/local/share/GeoIP if you installed from source and in /var/lib/GeoIP if you installed via yum. We also need a copy of the GeoLite City database. CD to the appropriate directory from the your installation
# cd /var/lib/GeoIP # wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz # gunzip GeoLiteCity.dat.gz
Configuring AWstats
AWstats can use a different configuration file for each web site. A "model" copy of the configuration is provided with the source code and this make a handy place to keep default configuration information you want to use on all sites. AWstats can also pull separate configuration files together, meaning we don't need to make copies of the "model" config, we can just include it and then override settings as necessary.
Each configuration file has a name, doesn't really matter what it is, just prefix it with "awstats." and suffix with ".conf"
/usr/local/etc/awstats/awstats.ninjafocus.net.conf:
Include "awstats.model.conf" LogFile="/var/www/vhosts/ninjafocs.net/logs/access_log" SiteDomain="www.ninjafocs.net" DirData="/var/lib/awstats/ninjafocus.net"
/usr/local/etc/awstats/awstats.model.conf:
LogFile="/var/log/httpd/access_log" LogType=W LogFormat=1 SiteDomain="ares.ninjafocus.net" AllowAccessFromWebToAuthenticatedUsersOnly=0 AllowAccessFromWebToFollowingAuthenticatedUsers="" AllowAccessFromWebToFollowingIPAddresses="" DNSLookup=1 DirData="/var/lib/awstats/default" CreateDirDataIfNotExists=1 BuildReportFormat=xhtml DirCgi="/awstats/cgi-bin" DirIcons="/awstats/icon" StyleSheet="/awstats/css/awstats_default.css" Expires=3600 AllowFullYearView=3 HTMLHeadSection="" HTMLEndSection="" Logo="awstats_logo6.png" LogoLink="http://awstats.sourceforge.net" BarWidth = 260 BarHeight = 90 DefaultFile="index.php index.htm index.html" NotPageList="css js class gif jpg jpeg png bmp ico swf" SkipDNSLookupFor="" SkipHosts="" SkipUserAgents="" SkipFiles="" SkipReferrersBlackList="" OnlyHosts="" OnlyUserAgents="" OnlyFiles="" LoadPlugin="tooltips" LoadPlugin="decodeutfkeys" LoadPlugin="hashfiles" LoadPlugin="hostinfo" LoadPlugin="geoipfree" # Make sure this is set to the right location for your install - CentOS users will have it as # shown, if you installed from source the path should be /usr/local/lib/GeoIP/GeoLiteCity.dat LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/lib/GeoIP/GeoLiteCity.dat" MiscTrackerUrl="/awstats/js/awstats_misc_tracker.js" LevelForBrowsersDetection=2 LevelForOSDetection=2 LevelForRefererAnalyze=2 LevelForRobotsDetection=2 LevelForSearchEnginesDetection=2 LevelForKeywordsDetection=2 LevelForFileTypesDetection=2 LevelForWormsDetection=2 ShowSummary=UVPHB ShowMonthStats=UVPHB ShowDaysOfMonthStats=VPHB ShowDaysOfWeekStats=PHB ShowHoursStats=PHB ShowDomainsStats=PHB ShowHostsStats=PHBL ShowAuthenticatedUsers=0 ShowRobotsStats=HBL ShowWormsStats=UVPHB ShowSessionsStats=1 ShowPagesStats=PBEX ShowFileTypesStats=HB ShowFileSizesStats=1 ShowOSStats=1 ShowBrowsersStats=1 ShowOriginStats=PH ShowKeyphrasesStats=1 ShowKeywordsStats=1 ShowMiscStats=a ShowHTTPErrorsStats=1 AddDataArrayMonthStats=1 AddDataArrayShowDaysOfMonthStats=1 AddDataArrayShowDaysOfWeekStats=1 AddDataArrayShowHoursStats=1 MaxNbOfDomain = 10 MaxNbOfHostsShown = 10 MaxNbOfLoginShown = 10 MaxNbOfRobotShown = 10 MaxNbOfPageShown = 10 MaxNbOfOsShown = 10 MaxNbOfBrowsersShown = 10 MaxNbOfScreenSizesShown = 5 MaxNbOfWindowSizesShown = 5 MaxNbOfRefererShown = 10 MaxNbOfKeyphrasesShown = 10 MaxNbOfKeywordsShown = 10 MaxNbOfEMailsShown = 20
Configuring Apache
<VirtualHost *:80>
ServerName stats.ninjafocus.net
DocumentRoot /var/www/vhosts/stats.ninjafocus.net/htdocs
CustomLog /var/www/vhosts/stats.ninjafocus.net/logs/access_log combined
ErrorLog /var/www/vhosts/stats.ninjafocus.net/logs/error_log
<Directory /var/www/vhosts/stats.ninjafocus.net/htdocs>
Options Indexes FollowSymlinks
AllowOverride none
Order allow,deny
Allow from all
</Directory>
ScriptAlias /awstats/cgi-bin /var/www/vhosts/stats.ninjafocus.net/awstats/cgi-bin
<Location /awstats/cgi-bin>
Options +ExecCGI
AddHandler cgi-handler .pl
</Location>
</VirtualHost>
Generating Report Data
Set up a cron job to update the report data every night - or as often as you like. Only new entries in the logs are processed each time.
17 0 * * * /bin/nice -n 10 /usr/local/share/awstats/awstats_updateall.pl now -awstatsprog=/var/www/vhosts/stats.ninjafocus.net/awstats/cgi-bin/awstats.pl -configdir=/usr/local/etc/awstats
Manually run the command to generate the initial report data. If you're sites have already been going for some time, this will take ages.
# nice /usr/local/share/awstats/awstats_updateall.pl now -awstatsprog=/var/www/vhosts/stats.ninjafocus.net/awstats/cgi-bin/awstats.pl -configdir=/usr/local/etc/awstats
Viewing the Reports
To view the reports use your web browser to go to http://stats.ninjafocus.net/awstats/cgi-bin/awstats.pl?config=<config_name>. The name of the config must match up with the name of a configuration file in /usr/local/etc/awstats/. For example the web site www.ninjafocus.net has a config filename of awstats.ninjafocus.net.conf and the URL used to view the stats is http://stats.ninjafocus.net/awstats/cgi-bin/awstats.pl?config=ninjafocus.net
