View Full Version : AWStats on secondary domains

09-25-2009, 07:06 AM
Lately I've noticed that the blog post on this is out of date so here is a more up to date version.

Step 1:
First we must change the apache configuration file. If you look at the very bottom of /etc/httpd/conf/httpd.conf (note you may have VirtualHost *:80 within the < and > tags, whatever you have make sure just to copy it)

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

We are going to add a single line to this file. We need to tell Apache that we want a custom log for this domain. 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.

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

Step 2:
We will need to restart the account. We can do so via the
/etc/init.d/httpd restart command from SSH or by using the "Restart Account" link on the left in Site Manager.

Step 3:
Once we've done this, we're ready to setup AWStats to start gathering stats from this new log. In the /etc/awstats directory you will see either awstats.conf or awstats.primarydomain.conf, lets make a copy of this file and name it awstats.secondarydomain.conf, replacing secondarydomain with your domain name of course. After this file has been copied, we need to make a change to it. Open the file up in your favorite file editor and look for a line that looks like this:

LogFile="/usr/local/awstats/tools/logresolvemerge.pl /var/log/httpd/access_log /var/log/httpd/ssl_access_log |"
This line might also look like:

We will need to change this line to look like this:

LogFile="/var/log/httpd/secondaryddomain_access_log" Just replace "secondaryddomain_access_log" with what you put after log/ in Step 1 above.

Next line we want to look for is

SiteDomain="primaryDomain.com" and
HostAliases="primaryDomain.com www.primaryDomain.com localhost" we simply want to change anywhere it says "primaryDomain.com" with your secondary domain. So in our example we will want to change these lines to look like:

SiteDomain="secondaryDomain.com" and
HostAliases="secondaryDomain.com www.secondaryDomain.com localhost" There is one more optional change you can make, I like to make this change but it is not nessessary. If you look for this line:
AllowToUpdateStatsFromBrowser=0 and change it to read:
AllowToUpdateStatsFromBrowser=1 This will enable an "Update Now" link within AWStats so you can have it update the stats instantly. NOTE: you must have the server parse the stats at least once before this link will work. Just use this command to parse the stats:

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

Step 4: (NOTE: You only need to do this if you have not done this before)
We need to tell the server that it should parse the new information automatically. To do this we want to edit the file located at /bin/web_logs.sh . Once you bring it up you may see something like this:

for i in `ls /var/www/cgi-bin/plugins/Webalizers 2>/dev/null`
cd /var/www/cgi-bin/plugins/Webalizers/${i}
/var/www/cgi-bin/plugins/Webalizers/${i}/webalizer.cgi 2>&1 >/dev/null

exit 0
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=primaryDomain or something like this:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=primaryDomain If your log looks like the first one, you MUST remove the "exit 0" line out of here. If you do not, your stats will not be calculated properly. What we want to do is replace the line that looks like
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=primaryDomain with this:
/usr/local/awstats/tools/awstats_updateall.pl now What this does is change AWStats so it will scan the /etc/awstats folder and parse and calculate all of the stats instead of just the single domain.

Step 4b: (optional, but recommended, you also don't have to do this more than once)
By default, the only time statistics are generated is when the log file gets above 1MB in size. We can have the server automatically parse the stats every night, even if the log doesn't get that big. All we need to do is SSH into the account, execute the following command:
editcron -e and find the line that looks like this:

58 1 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=primarydomain NOTE: the first two numbers, in my case 58 and 1 may change, I would recommend you leave these numbers the same. You would want to change the part in this line that looks like this:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=primarydomain to read:
/usr/local/awstats/tools/awstats_updateall.pl now so in my example it would read:
58 1 * * * /usr/local/awstats/tools/awstats_updateall.pl now
Once you've changed the line you can do control-x, hit the y key and then hit enter.

Step 5:
You're done! It is all setup! To access the stats you would go to http://primarydomain.com/awstats/awstats.pl?config=secondarydomainwhere secondary domain is the part in the .conf file between the awstats. and the .conf. So if I had awstats.mydomain.conf I would access it via http://primarydomain.com/awstats/awstats.pl?config=mydomain

Please note that this is not supported by WestHost Technical Support, if you have troubles you can post here so that we in the forums can help you

12-14-2009, 06:22 AM
Thank you for the very informative and clear information on setting up aw stats for a sub domain. I believe I did everything right but when I go to check out the stats it seems that it is not seeing the sub domain still. I have updated and Restarted My Account but it still is not picking up the stats. Any suggestions would be appreciated.

12-14-2009, 07:51 AM
Check to see if the second log is being written first.

CustomLog logs/secondaryddomain_access_log combined

Go to /var/log/httpd and see if the file secondaryddomain_access_log is there. Your actual file name may be different depending on what you entered. :) logs is actually a symbolic link to /var/log/httpd directory.

The other thing is this:

NOTE: you must have the server parse the stats at least once before this link will work. Just use this command to parse the stats:

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

Did you do that?

12-14-2009, 01:09 PM
I did check the access_log and it is there but I did not do the command. I am quite the novice so just to confirm so I don't ruin my account settings. I go into the file manager and click on "Execute a Command" and then type in "/usr/local/awstats/tools/awstats_updateall.pl now" and hit submit?

12-14-2009, 02:43 PM
I normally use Putty to establish an SSH session to run such commands but you can try it in the File Manager.

12-14-2009, 04:57 PM
Thank you for your input and yes I could do the command /usr/local/awstats/tools/awstats_updateall.pl now via File Manager. It actually was another issue (a spelling issue in the code). Thanks.