Webalizer and virtual hosts

WebalizerA very commonly used statstics program for the Apache webserver is the webalizer program that analizes httpd log-files and creates site statistics from that. But standard it’s configured for only one domain. As I am running multiple domains on my RedHat Enterprise Linux machine and want seperate statistics for them, some work had to be done.

First of all, your httpd.conf has to be edited. Every domain you’re running (so, every VirtualHost in your httpd.conf) and want statistics for, need a seperate log-file. So that would look like this:

<VirtualHost *:80>
   ServerName www.yourdomain.com
   DocumentRoot /var/www/sites/yourdomain/html/
   CustomLog /var/log/httpd/yourdomain-access_log combined

Do this for every VirtualHost you want statistics for. You can also (like I did) create a seperate error_log for each domain to easily see errors for each domain.

ErrorLog /var/log/httpd/youdomain-error_log

After this, create a directory inside the domain where you want your statistics to appear. I chose to create one directory on one domain and inside that directory a directory for each domain. You can create an index.html where you can link to the statistics for each domain, so that everything is in one place and you don’t have to go to each domain to see the statistics. But more on that later.

Now, a webalizer.conf for each domain has to be created. This file is standard in /etc, but to avoid a mess there, I created a new directory: /etc/webalizer. Copy the webalizer.conf from /etc into it, and rename it something like webalizer-yourdomain.conf. Fire up vi (or your favorite editor) and edit the file to your needs. Be sure to at least edit the following lines:

LogFile          /var/log/httpd/yourdomain-access_log
OutputDir        /var/www/yourdomain/stats
HistoryName      /var/lib/webalizer/yourdomain.hist
IncrementalName  /var/lib/webalizer/yourdomain.current
HostName         yourdomain

To get useful log, you can hide your own visits to it by editing the following line:


You can also put a hostname there or even a domainname and work with wildcards (*) as is explained in the text above the Ignore-area. It is useful to look at the output the first few days, as my computer appeared under different names: as my local IP-number, as my hostname, as the external IP-address and as the hostname that my ISP assigned to my connection. So I added these all 4 to the IgnoreSite part.

If you are running a CMS (Content Managing System) like Joomla or WordPress for example, maybe it is also useful to hide the administration-pages. For Joomla that would look like this:

IgnoreURL        /administrator*

Or if you’re running WordPress:

IgnoreURL        /wp-admin*

Copy and adjust this file for every domain.

One more step has to be taken to get this all working. As you look in /etc/cron.daily there is a file called 00webalizer. So these statistics are generated once a day. If that ain’t sufficient for you, you can copy or move this file to /etc/cron.hourly for example. Copy this file and name it something like webalizer-youdomain. Fire up vi and edit the options:

#! /bin/bash
# update access statistics for the web site    

if [ -s /var/log/httpd/yourdomain-access_log ]; then
   exec /usr/bin/webalizer -Q -c /etc/webalizer/webalizer-yourdomain.conf

After it looks like this, save it and exit and look if it works by executing the file. If everything goes well, your first statistics are in the outputdir you specified in /etc/webalizer/yourdomain.conf. And again, copy and edit this file for every domain. You can also put all these routines in one file, but I chose for seperate ones because that’s way it’s easier to move one of them to another cron interval, hourly for example, if you need updates more regularly.

As I mentioned earlier, I created one directory with an index.html and seperate directories inside that one, one for each domain. As I don’t want everybody to see all these statistics, I created a .htaccess file and put a password on the directory.

AuthName "Server Statistics"
AuthUserFile /var/www/sites/yourdomain/.htpasswd-stats
AuthType basic
Require valid-user

Be sure to specify the full path to the .htpasswd file, or it won’t work. Also be sure not to put the .htpasswd in a directory that is open to the internet. Placed it in a directory one level higher than html/. After creating the .htaccess file, you need to create the .htpaswd file. That’s done by executing this command in the direcotry you want the file to be created in:

htpasswd -c .htpasswd username

The username in this example is the username you want to give access to the directory and it asks for a password after executing the command. The next users you want to give access are done by the same command, only omitting the -c option, as this only is required to create the .htpasswd file.

Well, this is quite it. This is how it works for me, and this is a guide to set it up for you. Maybe you don’t like the directory-structure I suggested or you want someting else to do different: it’s all up to you! You are totally free in all of it!

One thought on “Webalizer and virtual hosts”

Leave a Reply

Your email address will not be published. Required fields are marked *