Blog

Setting up awstats for Mac OS X Server

By Chris Williams posted on May 7th, 2007

If you are using Mac OS X Server to host websites, you might want to be able to track how many folks are hitting your websites. One popular and free web statistics package is awstats.

Read on to find out how to setup awstats on Mac OS X Server.


This article discusses Mac OS X Server version 10.4.

Modify your logs
oYou should change your log format to one that contains more information than the default common format, and if you host more than one site you should tell the web server (Apache) to split out the logging so each site gets its own log.

-In Server Admin, go to the Web section then the Settings section. Click on the Sites tab and open the details for the site you are setting up awstats for. Once there click on the Logging tab. Make sure that ‘Enable Access log’ is checked. In the Location field for the Access log edit the log name so it contains the name of your site. For example, if it said ‘/var/log/httpd/access_log’ before, change it to ‘/var/log/httpd/[your site name]_access_log’

-while you are there, change the log format to ‘combined’

Server Admin log config

Setting up awstats on Mac OS X Server
o

Download the latest version of awstats (grab either the .zip or .tar.gz files)

Create a folder called awstats in your web documents folder, which is by default in /Library/WebServer. If you are keeping your web documents elsewhere, create your awstats directory there instead. The important thing is that the awstats folder be a subfolder of a web share.

Unpack the download, then place the contents in your awstats folder.

In Terminal, navigate to the tools subfolder of the awstats directory that you created. Next, run the awstats configure script by running ./awstats_configure.pl and answer the questions.
o-look for the section that asks you to define the config file name. Put your web site URL there (i.e. www.example.com) and take note of what you entered. A config file that you will need to edit later will be created with the name awstats.[your config name].conf in your awstats/wwwroot/cgi-bin/ directory.

You will likely need to edit your configuration file, awstats.[your config name].conf. The configuration files are well documented.

Edit the configuration file in your favorite text editor (vi, emacs)
look for the following lines and put in the appropriate values:

    o
  • -LogFile=”[path to the access log that you specified above]“
  • -default log format is Apache combined so as long as you chose that above you should be okay

    o

  • -SiteDomain=”[your site name]“
  • o

  • -DirData=”.”
  • -this is where awstats will put the database of site visitation data. Putting a “.” here will tell awstats to store its data in the same directory as the awstats.pl file.

o
Schedule awstats to update your statistics

There are several ways you can do this. Mac OS X Server already runs maintenance scripts each night. You can insert the awstats update script into the maintenance script by editing /etc/periodic/daily/600.daily.server

Insert these commands below the line containing “log_message(”Starting.”);”

log_message("update awstats web monitoring statistics");
\`/Library/WebServer/awstats/wwwroot/cgi-bin/awstats.pl -update -config=[config file name]\`;

Test out your awstats page by going to http://[your domain name]/awstats/awstats.pl?config=[config file name] in your web browser. The statistics will be updated every morning at 3:15am when your server maintenance periodic scripts normally run.

awstats sample

Bonus: setup geoip country location.

Awstats can display what country your visitors are hailing from if you enable the geoip plugin.

First you must install the Geo::IP::PurePerl module. You can do this using CPAN, the Perl module download and installation utility. Before you can use CPAN you must have XCode installed on your system and you will need to configure CPAN first which it will prompt you to do when you run it for the first time. After you have those dependancies out of the way, issue this command:

perl -MCPAN -e 'install Geo::IP:PurePerl'

Next you should download the free IP to country database from Maxmind and place it somewhere on your system. The awstats directory is one logical place for it.

Now edit the awstats config file for your site. Locate this line and uncomment it by removing the # and put in the correct path to the GeoIP.dat file you just downloaded.

#LoadPlugin="geoip GEOIP_STANDARD /pathto/GeoIP.dat"

Refresh your awstats page to see your handywork!

Posted in Mac OS X Server

Comments are closed.