Install awstats with apt-get install awstats. To get geostats working, so you can tell the countries of origin of your visitors, apt-get install libnet-ip-perl libgeo-ipfree-perl.
Drop this in /etc/apache2/conf.d/awstats:
Alias /awstats-icon/ /usr/share/awstats/icon/ <Directory /usr/share/awstats/icon> Options None AllowOverride None Order allow,deny Allow from all </Directory>
For each vhost you want to analyse, create a /etc/awstats/awstats.vhost.domain.co.nz.conf file, looking like such:
LogFile="/var/www/vhost.domain.co.nz/log/access.log" LogType=W LogFormat=1 LogSeparator=" " SiteDomain="vhost.domain.co.nz" HostAliases="localhost 127.0.0.1" DNSLookup=1 DirData="/var/lib/awstats" DirCgi="/cgi-bin" DirIcons="/awstats-icon" AllowToUpdateStatsFromBrowser=0 AllowFullYearView=2 LoadPlugin="geoipfree"
Use LogFormat 1 if you are using 'combined' Apache logs, which are used by default. Use LogFormat 4 otherwise
Some people like to cron a stats update to happen more often. I will be happy with once a day, so I'll use my daily logrotate time. I have a seperate logrotate file for each vhost:
/var/www/vhost.domain.co.nz/log/*.log { daily missingok rotate 7 compress delaycompress notifempty create 640 www-data www-data prerotate /usr/lib/cgi-bin/awstats.pl -config=vhost.domain.co.nz -update endscript }
You could put a cron fragment like this somewhere:
3,33 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.vhost.domain.co.nz.conf -a -r /var/log/apache/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=vhost.domain.co.nz -update >/dev/null
We will use Apache's .htaccess mechanism to ensure you can only see the stats if you know a password.
htpasswd -c /etc/awstats/awstats.htpasswd username
Now, edit /etc/apache2/sites-enabled/000-default, under <Directory "/usr/lib/cgi-bin">, add
AuthType basic AuthName "cgi-bin restricted" AuthUserFile /etc/awstats/awstats.htpasswd <Files awstats.pl> Require valid-user </Files>
Reload Apache, and try navigating to http://primary.sitename.co.nz/cgi-bin/awstats.pl?config=vhost.domain.co.nz.
I am only allowing cgi-bin on my primary host; a good compromise is to set up a redirect from http://vhost.domain.co.nz/stats/ to the primary hostname; in /etc/apache2/sites-enabled/vhost.domain.co.nz:
RedirectMatch permanent /stats http://primary.sitename.co.nz/cgi-bin/awstats .pl?config=vhost.domain.co.nz
One page links to AwStatsNotes: