nav-left cat-right
cat-right

AWStats

3.8 AWStats

Awstats is a web log analyzer that produces some good info. You have to modify your websites to load a javascript file if you want the full reports, but I've done that by placing the script on the footer of every page. You also have to ensure that your web logs are logging in Apache "combined" format.

3.8.1 Install AWStats

Visit the AWStats home page to get the download link for the latest tarball. Then do the standard wget/unpack:

  • cd /srv/www
  • wget http://prdownloads.sourceforge.net/awstats/awstats-[version]
  • tar zxvf awstats-[version]
  • mv awstats-[version] awstats

AWStats is Perl-based, so you'll need to enable cgi scripting under Apache for a particular directory in order to view output. We'll make that directory and copy our configs there, then set up scripting in Apache in a few minutes:

  • sudo mkdir /etc/awstats
  • sudo cp awstats/wwwroot/cgi-bin/awstats.model.conf /etc/awstats/
  • sudo vi /etc/awstats/awstats.model.conf

Now set up your awstats conf files from this base model file.

3.8.2 Install the GeoIP Perl module

I use the GeoIP analysis option with AWStats, so I need to install the Perl GeoIP plugin in addition to the normal GeoIP libraries I've already installed previously.

Run CPAN by typing:

  • cpan

If you haven't used cpan up until now, you'll have to fill in all the questions until you get to the actual cpan> prompt. I just type "no" at the first prompt to allow CPAN to try to automatically configure itself. Then:

  • cpan> install Geo::IP
  • cpan> exit

Done! Now AWStats can use GeoIP.

3.8.3 Configure AWStats

I generally keep one configuration file per site I wish to have analyzed, ie. /etc/awstats/awstats.[site name].conf. Copy and modify the awstats.model.conf file as needed:

LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
SiteDomain="your.site.domain"
HostAliases="localhost 127.0.0.1 REGEX[yourserver\.com$]"

That should be enough to get you up and running. If you want to analyze your first log, run /srv/www/awstats/wwwroot/cgi-bin/awstats.pl -config=[conf name] -update, where [conf name] is the awstats.[conf name].conf file of the configuration file in /etc/awstats.

3.8.4 AWStats Daily Analysis

What I normally do now is have Logrotate configured to rotate all my website log files each day (remember how we set them up in separate log directories on a per-site basis?) Once they've been rotated, I have an AWStats cron entry set up to analyze the day-old log. The cron entry looks like this (I usually have a user named "webcron" or something to handle all my website-related cron jobs):

30 4 * * * /srv/www/awstats/wwwroot/cgi-bin/awstats.pl -config=sitename -update

So at 4:30 every morning, awstats analyzes the log specified in the config file awstats.sitename.conf (which in my naming scheme will be /var/log/httpd/[sitename]/access_log.1).

3.8.5 Apache configuration

Now I set up an Apache virtual host so I can view the stats. Put this into one of your virtual host sites files. (p.s. I also create a DNS entry to get a stats.yoursite.com address that I can use to access this virtual host. You can just use an Alias directive instead if you don't feel like having a separate virtual host).

Here's the vhost entry I use:

<VirtualHost *:80>

ServerName stats.yourdomain.com
DocumentRoot /srv/www/awstats/wwwroot
ScriptAlias /awstats/ "/srv/www/awstats/wwwroot/cgi-bin/"
Alias /awstatsclasses "/srv/www/awstats/wwwroot/classes/"
Alias /awstatscss "/srv/www/awstats/wwwroot/css/"
Alias /awstatsicon "/srv/www/awstats/wwwroot/icon/"

<Directory "/srv/www/awstats/wwwroot">

Options None
AllowOverride All
Order allow,deny
Allow from all

</Directory>

</VirtualHost>

The aliases are to tell your webserver to run those URLs as scripts (AWStats is written in Perl, so Apache needs to be told to execute any URL inside that directory as a script).

Now you can go to http://stats.yoursite.com/awstats/awstats.pl?config=yoursite and get some web stats. Neat! As a final step, I generally use an Apache .htaccess file to put some basic HTTP Authentication on my AWStats area, just so people can't snoop my web stats.

  • Digg
  • del.icio.us
  • DotNetKicks
  • Slashdot
  • StumbleUpon