SoftwarePractice.org: Home | Courseware | Wiki | Archive

AWStats on TextDrive

From SoftwarePractice.org

There are some notes on the TextDrive forum about installing AWStats on your TextDrive account. I needed something a bit different, so I've written it down here. It will be useful for me so that I know what I've done later on anyway.

The following assumes that you know how to use a shell to untar files and move things around.

Credits

I used the following existing resources while doing this install and writing up these notes.

Contents

Goal

TextDrive gives you a single main domain, and a number of secondary domains. Each of them is a proper website in its own right, and has its own Apache configuration and (important for this page) log files. I want to use AWStats to analyze the log files of all my domains, and to generate a single location on my main domain where I can view them. While some of my domains are there to support other people (friends, musical ensembles that I sponsor, ...) I don't need them to see the results from AWStats. (For that, see SlimStat on CMSMadeSimple.)

AWStats has the option of generating static HTML pages, or of generating the pages dynamically. Since no-one but me is to have access to the AWStats output, I will use dynamic page generation. I also want access to the pages limited to me, although it's not all that important since nothing will link to them.

I don't need to run AWStats from the command line, or update stats via the Web. All I want is for AWStats to analyze the log files and provide stats viewable through my browser.

TextDrive Directory Layout

I have the "new" TxD directory layout. I provide it here so that following instructions makes sense, in particular for anyone with the "old" layout or who is perhaps installing AWStats on a different host.

/home/users/me/
               cgi-bin/                    (main domain CGI)
               logs/                       (main domain log files)
               web/public/                 (main domain PHP/HTML files)
               domains/
                       other1/             (secondary domain root)
                               cgi-bin/    (secondary domain CGI)
                               logs/       (secondary domain logs)
                               web/public/ (secondary domain HTML/PHP)
                       other2/             (another secondary domain)
                               ...etc

(For the sake of this example, the main domain name is me.com, and there are two secondary domains called other1.com and other2.com.)

Basic Install

This part is straightforward. I didn't create all the aliases suggested in the AWStats documentation, as they appear to be unnecessary! Thanks to digerati consulting for showing me that.

  1. Download the current release from the AWStats site and untar the distribution. You get a structure that looks like this:
    awstats-6.5/docs/
                tools/
                wwwroot/
                        cgi-bin/
                        classes/
                        css/
                        icon/
                        js/
    
  2. Move the awstats-6.5/wwwroot/cgi-bin directory into your main domain's CGI directory. Rename it awstats.
  3. Move the awstats-6.5/wwwroot/ directory into your main domain's public directory. Rename it to awstats as well.
  4. Create a directory for holding the awstats data files. I put an awstats_data directory in my logs directory. You will now have a structure that looks like this:
    /users/home/me/
                   cgi-bin/                    (main domain CGI)
                           awstats/            (awstats executables}
                   logs/                       (main domain log files)
                        awstats_data/          (AWStats data files)
                   web/public/                 (main domain PHP/HTML files)
                              awstats/         (awstats utilities -- css and js)
                   domains/
                           ...etc
    
  5. Create the configuration file. Copy the awstats.model.conf file, call the result awstats.me.com.conf. (me.com is your main domain.) This file contains a lot of configuration directives. For now, let's just create a basic one that works on the main domain. Edit the directive below as shown (ignore the rest):
    LogFile="/users/home/me/logs/access_log"
    SiteDomain = "www.me.com"
    DirData="/users/home/me/logs/awstats_data"
    DirIcons="/awstats/icon"
    
  6. In order to make visiting countries display, you need to use the GeoIP plugin. See the .conf file for more info. Here's what my configuration line looks like:
    LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
    

    (Note: TextDrive has GeoIP already installed, you don't need to do anything else to make this work.)

  7. Test the basic setup. Run the script to analyze the current log file:
      perl ~/cgi-bin/awstats/awstats.pl -config=me.com -update
    

    Load the awstats script into your browser to see the result:

      http://www.me.com/cgi-bin/awstats/awstats.pl
    

    You should get a stats page with some hits (hopefully!) for today. If there's an error, better stop now and fix it before proceeding.

Complete Install

Since the log files are rotated, the best way to process them is to run awstats on yesterday's log file. In other words, rather than trying to analyze the current logs just before they get rotated, wait a while and then analyze the archived log files. I schedule the run at 2:15 am, which should be a fairly quiet time.

The other thing we need to do is add all the secondary domains.

  1. Modify the configuration file to read yesterday's log file (from scottj):
    LogFile="/usr/bin/gzip -d < /users/home/me/logs/access_log.%YYYY-24%MM-24%DD-24.gz |"
    
  2. Create configuration files for each auxiliary domain, by copying your main configuration file. These take the name awstats.other1.com.conf, awstats.other2.com.conf, and so on. The key parameters to change are:
    LogFile="/usr/bin/gzip -d < /users/home/me/domains/other1.com/logs/access_log.%YYYY-24%MM-24%DD-24.gz |"
    SiteDomain = "www.other1.com"
    

    (DirData and DirIcons are the same as for the main domain.)

  3. Create a script to update all of the domains. Something like this will do the trick:
    #!/usr/local/bin/bash
    for domain in \
            me.com \
            other1.com \
            other2.com
    do
      /usr/bin/perl /users/home/me/cgi-bin/awstats/awstats.pl -config=$domain -update
    done
    

    Save it as dostats.sh and set permissions to 700. Run it to make sure everything works so far:

      ./dostats.sh
    

    If you would rather have the list of domains generated automatically, the following script will look at the configuration files and get the domain names from there:

    cd ~/cgi-bin/awstats
    for domain in `ls awstats.*.conf | sed -e "s/awstats.\(.*\).conf/\1/"`
    do
      if [ $domain != 'model' ]
      then
        /usr/bin/perl /users/home/me/cgi-bin/awstats/awstats.pl \
                       -config=$domain -update
      fi
    done
    
  4. Add an entry to crontab to run awstats nightly. At the command line, type 'crontab -e' and enter the following line (you will be in vi, so type 'i' to enter edit mode, Esc to exit edit mode, :w to write, and :q to quit).
    15 10 * * * /users/home/me/cgi-bin/awstats/dostats.sh
    

    (Note: this line runs the job at 10:15 am. Since the TextDrive servers are on GMT, the job runs at 2:15 am in California, give or take.)

Create Links

Now, you can access each stats page individually, using eg

http://www.me.com/cgi-bin/awstats/awstats.pl?config=other2.com

It would, however, be nice to have an easy way to link to all the subdomains. Here are a few ways.

  1. Create an HTML page somewhere in your web directory that looks like this:
    <html><body><ul>
    <li><a href="/cgi-bin/awstats/awstats.pl?config=me.com">me.com</a></li>
    <li><a href="/cgi-bin/awstats/awstats.pl?config=other1.com">other1.com</a></li>
    <li><a href="/cgi-bin/awstats/awstats.pl?config=other2.com">other2.com</a></li>
    </ul></body></html>
    
  2. Modify awstats.pl to generate links to each domain's stats. Open awstats.pl and search for these lines:
                            # Print Statistics Of
                            if ($FrameName eq 'mainleft') { 
    

    Inside that block is a print statement; right after the print statement (just before the close brace), insert this code:

    foreach my $domain (
        'me.com',
        'other1.com',
        'other2.com') {
         print "<tr><td class=\"awsm\"> \
                <a href=\"/cgi-bin/awstats/awstats.pl?config=$domain\" \
                   target=\"_top\">$domain</a></td></tr>\n";
    }
    

    You will, of course, have to update this code every time you add a new domain.

  3. Use the following code instead of the above. This code gets the domain names from the list of awstats config files:
    chdir("/users/home/me/cgi-bin/awstats");
    while (<awstats.*.conf>) {
      s/awstats.//;
      s/.conf//;
      if ($_ ne "model") {
        print "<tr><td class=\"awsm\"> \
               &loz; <a href=\"/cgi-bin/awstats/awstats.pl?config=$_\" \
               target=\"_top\">$_</a></td></tr>\n";
      }
    }
    
Now load it and see if it works:

http://www.me.com/cgi-bin/awstats/awstats.pl

And... that's about it! Now just wait until tomorrow morning to see if your cron job ran.

Restrict Access

You don't really want crawlers running through your stats pages. You could add them to you robots.txt file, but it's probably easier to simply require a password for access.

(Not done yet.)

Personal tools