To administer your WestHost account, please enter your
Domain Name or Server Manager Username.

AWStats and Multiple Domains

Seasons are changing, there is no doubt. There is no other place that this becomes more evident than in the WestHost Technical Support Department. With the decrease in the temperature outside we have seen an increase in the volume of contacts we see on a weekly basis. I suppose that it is inevitable, when people migrate indoors some will probably land behind a monitor and a keyboard. We are also approaching the holiday shopping season and reliability, preparedness, and tracking have become hot topics.

Recently we have seen an increase in questions regarding site statistics and how to best utilize some of our applications to analyze your site traffic. WestHost offers a great statistical application called AWStats. AWStats gives you excellent statistical information on who is visiting your site. As a Web master, you might use that data for the purpose of marketing or maintenance. For instance, AWStats tells you which search engine an end user used to find your site, and the keywords they typed in the search box. AWStats tells you how many visitors you’ve had over a given period of time, what pages they viewed, the browser they used, and a whole lot more. Many of you have asked if you can use AWStats to track multiple domains you have hosted within your single Virtual Private Server. The answer is yes you can. It is fairly easy. I will point out the key steps and common traps. I know that most of you don’t want to see anything too confusing, but would rather have a few things pointed out in plain English, so that is exactly what I intend to do. I’ll just go ahead and dive right in.

First of all, we need to have an idea of what AWStats really does on a fundamental basis. The application is going to parse the access logs that Apache keeps of all of the visitors to your site looking for visit information. From the chaos therein, it will create its own data files. Those data files will then be utilized to populate the pages that you see when you view your statistics. The problem is that by default, Apache will place all of the visit information into a single access log. Now that we understand what Apache and AWStats are going to do we can extrapolate what we need to do to accomplish our task. First we need to configure Apache to separate the access logs by domain and then AWStats to parse the separate logs accordingly. Simple enough right? Yep!

The first step is to configure Apache to write its separate access logs. This can be accomplished by editing the Apache configuration file, /etc/httpd/conf/httpd.conf. If you open and review this file, it can look confusing. I certainly thought so the first time I opened it up for some “surgery.” Not to worry. If you handle directions like the average Joe, you won’t have any trouble. Now one thing that you have to consider is that Linux doesn’t really like to interact with configuration files that have been written or edited by a text editor that will write files in a DOS format. If you are a Windows user and are not editing this file right on the server, just use Notepad, upload the edited file and you should be just fine. You could also utilize the text editor built into File Manager to complete your editing. Now that you know which file we will be editing, and just how we are going to do it, you probably want a few examples. For simplicity sake I am going to utilize primarydomain.com and secondarydomain.com in my explanations. Once we have the config file open we will be looking for the VirtualHost entry for the secondary domain. It will be towards the bottom of the file and will look like this:

VirtualHost */>
ServerName secondarydomain.com
ServerAlias www.secondarydomain.com
DocumentRoot /var/www/secondarydomain
/VirtualHost

We are going to add a little something to it. We need to tell Apache that we want a custom log for this domain. We will be adding the CustomLog directive for this virtual host just below the DocumentRoot directive. Generally we will want to have the new logs written to the same directory as they would be by default, we would just want to write them to a new file name, maybe something like secondarydomain_access_log. Here is an example using the information above:

VirtualHost */>
ServerName secondarydomain.com
ServerAlias www.secondarydomain.com
DocumentRoot /var/www/secondarydomain
CustomLog logs/secondaryddomain_access_log combined
/VirtualHost

This entry will write the access log for secondarydomain.com to /var/log/httpd/ and it will be named secondarydomain_access_log. Once the file is modified and saved or uploaded, we will want to give Apache a nice gentle restart. This can be accomplished from within Site Manager or from the command line by issuing the “apachectl graceful” command. There is a catch to writing to separate access logs. By default they won’t be rotated. That may not sound like much but think about this, we have done such a good job to configuring Apache to write this log separately that it will happily do our bidding without question. Eventually our new log file will grow to an unmanageable size. We’ll need to talk about this later on. For now, let’s get back to our task at hand.

Now that we have got our logs separated, let’s tell AWStats what to do with them. We need new, separate config files for each of the newly separated domains. Relax, we have good templates to work with. The AWStats configuration files are located in /etc/awstats. Take a quick look at this directory. As long as you have installed AWStats you will see a file named awstats.primarydomain.com.conf. Let’s make this a simple as possible, just make a copy of that file, but name it awstats.secondarydomain.com and save it to /etc/awstats. Now on to the fun stuff, we need to edit our new file, open the file up and let’s get to work. The first directive we need to find is the log file directive. Look for a line like the example below:

LogFile="/var/log/httpd/access_log"

As you can see by default this configuration will pull data from the standard log. Simply change this file to point to our new log file(s). Make it look similar to the example below.

LogFile="/var/log/httpd/secondarydomain_access_log"

Next we need to change the SiteDomain and HostAliases directives to reflect the secondary domain name rather than the primary domain name. They will look like this and will be on line 153 and 168 or there abouts:

SiteDomain="primarydomain.com"
HostAliases="primarydomain.com www.primarydomain.com 127.0.0.1 localhost"

Modify them to reflect the secondary domain.

SiteDomain="secondarydomain.com"
HostAliases="secondarydomain.com www.secondarydomain.com 127.0.0.1 localhost"

Now just save any changes you made. There is no need to restart anything here but we do need to check our work. Let’s see just how good we did. First we need to give Apache something to log in our new access logs so open a browser and go visit your secondary domain. Then, navigate to your AWStats Web interface, http://primarydomain.com/awstats/awstats.pl?config=primarydomain.com. You will notice that we specified which set of stats we wanted to view by passing the config variable in the URL. Lets view the statistics for our secondary domain now, navigate to http://primarydomain.com/awstats/awstats.pl?config=secondarydomain.com. Upon initial access you may think that broke something. The statistics are not processed automatically. Not to worry, the developers of AWStats thought of this and provided us a link right at the top of the page to “update now.” Don’t hesitate, click that button, you know you want to. If all went well and you didn’t stress too much you should see a result that will contain stats that have been collected since we restarted Apache. Way to go! We are almost done.

Earlier I had made mention that the new access logs wouldn’t be rotated and eluded to the fact they would just continue to grow until they filled your disk space I also highly doubt that you want to click the “update now” button and wait for AWStats to finish updating each domain each time you want to view your statistics. Your account will already be scheduled for log rotation on a daily basis, that is unless you have edited your crontab. Ah yes, the crontab, what a wonderful tool, but we’ll leave that for another discussion. Back to logrotate, we simply need to ensure that our new logs and the AWStats updates for secondary domains are included. This is also pretty slick. We need to edit the logrotate.conf file located in the /etc/ directory. Crack it open, we’ll get this done really quickly. In that file, on about the ninth line you will see the entry for the primary access log. Here is an example:

/var/log/httpd/access_log /var/log/httpd/agent_log /var/log/httpd/error_log /var/log/httpd/
referer_log
/var/log/httpd/ssl_request_log /var/log/httpd/ssl_engine_log {

Simply add your new access log files to the end of the line, but before the {

/var/log/httpd/access_log /var/log/httpd/agent_log /var/log/httpd/error_log
/var/log/httpd/referer_log /var/log/httpd/ssl_request_log /var/log/httpd/
ssl_engine_log /var/log/httpd/secondarydomain_access_log {

That will rotate our log files and manage their size. This will compress and archive our logs for a short period of time. Eventually logrotate will also delete the log files but only after adding our precious stats to the AWStats data files. Logrotate is a discussion for another time as well. Don’t close that file though, we aren’t done yet. There is one more entry we need to make to cause AWStats to update before the logs are rotated. Just below prerotate on about the 13th line of the file, you will see the following:

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=primarydomain.com

We need to insert a new line just below it and add our secondary domain name. Just make it look like this:

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=primarydomain.com
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=secondarydomain.com

Save your changes and give yourself a pat on the back. We are done! AWStats will now show you stats separated by domain name. We have discussed a couple of simple changes, but those simple changes will provide you some significant information.

This entry was posted in Promotions and Company News, Technical Support. Bookmark the permalink. Both comments and trackbacks are currently closed.

17 Comments

  1. Karen
    Posted November 16, 2007 at 5:31 pm | Permalink

    Excellent article. I cannot wait to give this a try. Thanks for posting this is such great detail. So now you know, someone is actually reading this stuff!!

    I have only recently started to share domains on accounts, and this information is timely. I’ve been using AWStats for many years and will say that it is a great site stat analyzer.

  2. Posted November 20, 2007 at 5:42 pm | Permalink

    This is a great tutorial. You may want to mention the command:

    /usr/local/awstats/tools/awstats_updateall.pl now

    which will update all the configs in /etc/awstats

    Also, my prerotate statement refers to /bin/web_logs.sh which has the awstats update command in it. Since the logrotate script calls this script, does it need to be edited? I would think that changing the web_logs.sh file to use the updateall script would be enough.

  3. Posted December 5, 2007 at 12:15 pm | Permalink

    This worked WONDERFULLY! I’ve been wanting to do this for some time but couldn’t find good directions until now.

    My only problem was the permissions on my httpd.conf file — I did not have proper permission to edit the file. A quick call to Westhost support corrected that. THANKS!

  4. Posted January 7, 2008 at 1:33 am | Permalink

    very interesting.
    i’m adding in RSS Reader

  5. Posted February 4, 2008 at 12:23 pm | Permalink

    Dan is the man! This is amazing. I will say I was going insane when altering the files from the manager online… Do not use Firefox! I was pulling my hair out because lines I was looking were not showing up the same is if I downloaded the .conf files. Crazy… Once I used another browser, it was a piece of cake. Thanks Dan!! R

  6. Posted February 18, 2008 at 3:05 pm | Permalink

    Thanks for this step by step guide. It looks simple enough but editing these configuration files really makes me nervous.

    I have taken your advice to heart Rich and will try to do this with fireftp or Dreamweaver (IE as a last resort).

  7. Posted April 19, 2008 at 2:58 pm | Permalink

    A great guide, but I had to chat with tech support to get it right. In the logrotate.conf file, line 13, there is a reference to /bin/web_logs.sh. I replaced this line with the code suggested in the instructions, for each secondary domain, but I imagine you could also put these instructions in web_logs.sh. Also, I could not find an “update now” button on my version of AWSTATS (6.6 build 1.887), so I updated using SSH (or sitemanager) with the command “/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=sitename”. Note that this command did not work unless the .com (or other domain type) was left OFF of the command. Not exactly sure if logrotate.conf should follow the same syntax, but I changed it there as well. Now, I have stats for 6 different domains!

  8. Rick Hocutt
    Posted May 19, 2008 at 10:46 am | Permalink

    This is a great guide thanks!

    I did get stumped on this…

    Upon initial access you may think that broke something. The statistics are not processed automatically. Not to worry, the developers of AWStats thought of this and provided us a link right at the top of the page to “update now.”

    I didn’t have the “update now” link. After searching I found that changing the line in your awstats.mynewsite.conf file about line #238 from this:

    AllowToUpdateStatsFromBrowser=0
    to this:
    AllowToUpdateStatsFromBrowser=1

    allowed the link to appear.

  9. Ray
    Posted August 17, 2008 at 5:45 pm | Permalink

    Outstanding Article! I am not hosted by Westhost right now. I’m only poking around to see what kind of support was provided. If this is any indication of the support Westhost provides, I’m sold! My current host (also deicated IP, VDS) doesn’t provide near this detail.

  10. Ray
    Posted August 17, 2008 at 5:49 pm | Permalink

    And now that I think about it, I asked them this very question (about how to break my logs up into individual domains) and I was told it couldn’t be done! I figured it out on my own but it took me over two weeks in my spare time. I am signing up for you Summer Special when I get home.

  11. Posted September 27, 2008 at 6:01 am | Permalink

    Everything is as you said except the line after the prerotate line in the logrotate.conf file.

    Instead of this line:

    /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=primarydomain.com

    I have only

    /bin/web_logs.sh

    Why don’t I have the line you show?

  12. Posted February 5, 2009 at 4:08 pm | Permalink

    I followed through this article … and the comments (be nice to get an updated article) and I now have things working without error messages and I can see the separate logs being collected, but when I go to look at the stats with config=otherdomain.com I am getting the stats for the main domain and its name shows in the upper left corner. What’s missing?

  13. Excell
    Posted February 7, 2009 at 4:41 am | Permalink

    Dan,

    Just go to /bin directory and find web_logs.sh. Open it and you’ll find /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=primarydomain.com I think the new line should be inserted here for the secondary domain name.

  14. Posted February 7, 2009 at 1:05 pm | Permalink

    From the forum on sourceforge, I found the answer. The config= needs to point to the short form that one has used in the configuration files, not the actual full domain name. E.g., in the configuration, I referred to bstw for bstw.com and reviews for ReviewsByTdeV.com so the config= has to point to bstw and reviews respectively, not bstw.com and reviewsbytdev.com.

  15. John
    Posted September 17, 2009 at 9:19 pm | Permalink

    Would love to get updated instructions on this, after following them to the letter I get the same problem Excell has.

  16. Posted May 19, 2010 at 6:49 am | Permalink

    Thank you for writing such an appealing post. Normall I see the same thing and it starts to get on my nearves. Thanks again and I’ll be back for more.

  17. Posted July 26, 2010 at 12:39 pm | Permalink

    We have a more recent post for AWStats on secondary domains here:
    http://forums.westhost.com/showthread.php?p=46051

    Hope that helps.

    Isaac Furniss
    Technical Support Representative
    WestHost
    Phone: 1-800-222-2165
    FAX: 435-755-3449

Copyright © 1998–2014, WestHost. All rights reserved.  |  WestHost / Believe in Better Hosting. Privacy Policy