Configuring a single AWStats site for multiple domains on Dreamhost
AWStats is one of the more popular free open source statistics packages available. Dreamhost doesn't make it automatically available, you need to install it yourself. Dreamhost has a number of good wiki articles on installing AWStats, but they presuppose installing in a website subdirectory. In my case, I wanted a dedicated statistics website for displaying statistics from other websites.
The following are notes I made while installing AWStats. AWStats isn't intended for install exactly the way I did it, but this configuration does work. Ostensively I'm making them available so they will benefit others, but in reality I'm posting them here so I can find them again if I need them! :-)
The source information came from the Dreamhost wiki articles. These are listed in the Reference section at the end of this article.
The Site Layout
There will be a single site, awstats.mydomain.com, that presents an index of statistics pages. This site runs under the username statsuser. There are two sites: www.example1.com and www.example2.ca. These run under the user names user1 and user2 respectively. Log files can only be read from their user account. To get around this, the cron job that updates the stats site must run from user1 and user2. Through group permissions, these accounts can write into the statsuser directory space.
Using Dreamhosts standard method of creating websites, we have the following:
- username: statsuser
home directory: /home/statsuser
web directory: /home/statsuser/awstats.mydomain.com
- username: user1
home directory: /home/user1
web directory: /home/user1/example1.com
log directory: /home/user1/log/example1.com/http
- username: user2
home directory: /home/user2
web directory: /home/user2/example2.ca
log directory: /home/user2/log/example2.ca/http
This installation must be done from the Unix command line.
- If you haven't already, create your stats website in the Dreamhost control panel
- Log onto the statsuser account
- Get a copy of AWStats:
$ wget http://awstats.sourceforge.net/files/awstats-6.6.tar.gz
- Extract the file:
$ tar xfzv awstats-6.6.tar.gz
- Copy the AWStats files into the web directory:
$ cp -R awstats-6.6/* awstats.mydomain.com/.
- Move into the web directory:
$ cd awstats.mydomain.com
- Create a data directories for the websites:
$ mkdir data
$ mkdir data/example1
$ mkdir data/example2
- Move the wwwroot contents into the actual web root directory (this is were the AWStats install assumptions don't match the Dreamhost reality):
$ mv wwwroot/* .
$ rmdir wwwroot
- Move into the cgi-bin directory:
$ cd cgi-bin
- Create configuration files for the first websites:
$ cp awstats.model.conf awstats.example1.conf
- Update the config files for the first example1.com:
LogFile="/home/statsuser//home/statsuser/awstats.mydomain.com/tools/logresolvemerge.pl /home/user1/logs/example1.com/http/access*.* |"
HostAliases="localhost 127.0.0.1 REGEX[example1\.com$]"
- You should now be able to try out your website:
If everything is configured properly, you'll see an page of empty statistics.
- Log into the user1 account, preferably in a second shell. Alternatively you can
sudo user1from your existing login.
- To populate the statistics, you need to run the command line update:
$ /home/statsuser/awstats.mydomain.com/cgi-bin/awstats.pl -config=example1 -update
If this command completes correctly, you're golden. You'll now see statistics on your stats web page.
- Configure cron (
crontab -efrom user1 account) to run regular updates. The following cron command will run the update once a day at midnight:
0 0 * * * /home/statsuser/awstats.mydomain.com/cgi-bin/awstats.pl -config=digitaldoodles -update
- Set up an index.html page in the /home/statsuser/awstats.mydomain.com directory for when we hit the website. For example:
<p><a href="/cgi-bin/awstats.pl?config=example2">Example2.ca Stats</a></p>
- Set up website security using the Dreamhost control panel
Navigate to Goodies : Htaccess/WebDAV : www.awstats.mydomain.com
Check password protect and configure a username/password
- Repeat the setup for the second and subsequent websites
There's a number of other AWStats configuration changes you'll probably want to make, such as eliminating your own IP address from the statistics (i.e., SkipHosts directive). The configuration file is fairly well documented.