Our Apache web server handles more than two dozen virtual hosts, and we are all keen to see statistics about our visitors: From where they are, which pages are most frequented, which search terms are used to find us and so on. A nice tool to analyze the log files and generate HTML statistic pages from them is AWStats.
The stock AWStats on Debian is unfortunately only useful for a single vhost. It further does not keep the full historic data (detailled montly stats) and does not generate index files for them (since it doesn't need to).
To help with that situation, I built my awstats-helper scripts. Written in PHP, they do the following things:
- Generate detailled monthly statistics for each vhost
- Keep an archive of the monthly statistics
- Generate an index page for each vhost so you can access the different months easily
- Generate an index page for all vhosts for easy navigation between vhosts
Installation
$ cd /usr/local/src $ git clone git://git.cweiske.de/awstats-helper.git $ cd awstats-helper
Setup
First, copy config.php.dist to config.php and adjust it. Usually you only need to change the htmldir setting and point it to the directory you want the HTML files generated in.
Then create a awstats config file for each vhost in /etc/awstats/ and call it awstats.foo.example.org.conf. Put the following lines in it:
Include "/etc/awstats/awstats.conf" LogFile="/var/log/apache2/foo.example.org-access.log" SiteDomain="foo.example.org" DefaultFile=""
Now the initial setup is done and we can run the initial data collection:
$ php update-sites.php $ php create-historic.php
If that worked out, add two cronjobs: One to generate today's month's data every couple of hours, and one to finish last month's data at the next month:
$ crontab -e # enter the following: 5 */6 * * * php /usr/local/src/awstats-helper/update-sites.php 5 3 1 * * php /usr/local/src/awstats-helper/update-lastmonth.php
This updates the current data every 6 hours and updates last month's data 3:05 on the first of each month.
That's it! Happy analyzing.