Web server log stats for multiple vhosts

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:


$ cd /usr/local/src
$ git clone git://git.cweiske.de/awstats-helper.git
$ cd awstats-helper


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"

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.

Written by Christian Weiske.

Comments? Please send an e-mail.