AWStats Multi-Site Setup

5.00 avg. rating (97% score) - 3 votes

Here’s how to install and configure AWStats to compile separate statistics about multiple Apache sites or virtual hosts running on a single server. This can be done when you configure each Apache site or virtual host to use a different access log file.

The following instructions have been tested on Ubuntu 12.04.

Install

Configure AWStats for the default site

Edit the /etc/awstats/awstats.conf.local file and not the master configuration file. The main awstats.conf file is a good reference for all the configuration options, of which there are plenty.

The only thing you really need to start gathering stats for your default-site, is enter your web server’s default site domain name /etc/awstats/awstats.conf.local:

That is all that is needed for AWStats to make statistics out of the default site. We will add more configuration files later, one for each site or virtual host we want to get statistics for. But we must fix a couple of things first.

Fix log file permissions

AWStats update script will run every 10 minutes as the user “www-data” (see /etc/cron.d/awstats). The Apache log files are by default not readable by the user www-data, so something must be done about that.

Edit /etc/logrotate.d/apache2 and give Apache log file read permissions to everybody. This may not be a good idea on a server with untrusted users with shell access, but mine has none.

Change the following line:

To:

Save, and then change the permissions of the existing log files:

Also, give permission to access the directory:

Ensure logrotate does not skew your statistics

AWStats runs every ten minutes, but logrotate might rotate a log file whenever it gets full, which will cause AWStats to miss some hits.

To ensure AWStats update script is always run before a logfile is rotated, we need to add a script for that. Add the following directory:

Add the update script:

Give execute permission:

At this point, you can run the statistics collector from the command line:

If there are no error messages, you should now have up-to-date statistics collected. Let’s get a site up and running to display the stats.

Configure Apache

Now that we have some real data, let’s set up a location where we can actually take a look at it. There’s an example Apache configuration file in /usr/share/doc/awstats/examples/apache.conf. But don’t copy it directly to Apache configuration directory. I added something like this to my default site file under /etc/apache2/sites-enabled:

That will require a username and password to access the stats. It is a good idea to use an SSL-secured version of the default site, and use that instead of unsecured one. You can run “a2ensite default-ssl” to enable the default SSL site.

The above configuration will actually from now on require a password for all your cgi scripts dwelling under /usr/lib/cgi-bin, so if you have something there you wish not to protect, move the awstats.pl to somewhere else and secure that instead.

To add the username and password for access:

Reload Apache configuration:

And then point your browser to http(s)://my.domain/awstats.pl to see some statistics!

Next, let’s move on to configuring separate statistics for multiple sites.

Configure AWStats for multiple sites

Place all additional configs in /etc/awstats/. Name the new configs “awstats.” + domain.name + “.conf”, eg. awstats.my.other.domain.conf.

In each file, include the main awstats.conf file. The first line should be:

After that, we need to configure at least the SiteDomain directive, the location of the Apache log file to scan, and place to put the statistics data. For example:

Make sure you get the LogFile path right (take a look at your Apache configuration to find out where it should be).

Also, create the directory for the statistics:

The next time AWStats runs, within the next 10 minutes, it will collect statistics about this other site. If you are impatient, or want to see if you made any mistakes with your configuration, you can run it manually:

Now we have data for this site.

Repeat the procedure for all other sites you have:

  1. Add a configuration file
  2. Create a stats directory with the right permissions
  3. Gather stats

Accessing statistics for other sites than the default-site

To see the statistics, browse to your default site’s awstats.pl script, but give it a “config” url parameter:

http(s)://my.domain/awstats.pl?config=my.other.domain

You can also configure AWStats separately for each site’s Apache configuration file, so you can use URLs like this: http(s)://my.other.domain/awstats.pl.

6 thoughts on “AWStats Multi-Site Setup”

  1. fantastic tutorial and followed it to the T, got an issue though and have this error
    “/etc/profile.d/resize.sh: [[: not found”
    any advice?

    1. The /etc/profile.d directory should contain shell startup files. I don’t think that resize.sh is related to anything on this page. You should take a look at the file and see what is in it.

      The “[[: not found” sounds like the bash expression evaluator “[[” is being called but the executing shell is not bash but something that does not have that. Most likely /bin/sh.

  2. Thank you for a brilliant and clear tutorial. Followed and it sorted out my earlier mess and worked, mostly.

    sudo su -l -c /usr/share/awstats/tools/update.sh www-data
    … this only updates stats for the core domain but not the additional virtual host site

    yet, this does work – manually, but not automatically…
    /usr/lib/cgi-bin/awstats.pl -config=correctly.entered.site -update

    i cannot find what i’m doing wrong here. Can you help?

  3. if you will set automatical update, /usr/lib/cgi-bin/awstats.pl -config=correctly.entered.site -update use in programs cron in linux.

  4. for anyone stuck at the line ‘su -l -c /usr/share/awstats/tools/update.sh www-data’, simply do ‘su -l www-data -s /bin/bash’

Leave a Reply