Installing AWStats on CentOS

Posted in Apache and Linux/Unix/BSD -

AWStats provides a useful overview of website statistics from your Apache log files. There is no automatic way to install AWStats on CentOS using yum, so this article looks at how to install AWStats on CentOS. The instructions below should also work on other Linux distributions that do not have an automatic way of installing AWStats.

The first thing to do is to download AWStats from the AWStats Download Page on Sourceforge. If you have an RPM based Linux distribution, such as CentOS, Red Hat Enterprise Linux or Fedora, then you can get the RPM version; for non-RPM based distros you can instead get the .tar.gz version.

As at the time of posting this article, the current version of AWStats is 6.7, as shown in the example wget downloads below.

wget http://example.com/sourceforge/awstats/awstats-6.7-1.noarch.rpm
OR
wget http://example.com/sourceforge/awstats/awstats-6.7.tar.gz

An an RPM based distribution, you would install AWStats using the command below, run either as root or with sudo.

rpm -ivh awstats-6.7-1.noarch.rpm

This installs AWStats to /usr/local/awstats. If you don't have an RPM based distribution, or prefer to extract AWStats to a different directory, then it's just a matter of downloading the .tar.gz file to the appropriate location and executing the following command:

tar -zxf awstats-6.7.tar.gz

AWStats is now installed, but you may need to make some minor modifications to the Apache configuration file in order to use it via a web browser.

The AWStats Perl script has a .pl extension. By default on CentOS, only .cgi scripts are interpreted as CGI Scripts, so you'll need to add the .pl extension as a cgi-script. This can be done either gobally in the /etc/httpd/conf/httpd.conf file, or just for this AWStats installation.

To make the change globally, open up the /etc/httpd/conf/httpd.conf file in your favourite text editor, either as root or using sudo, and change

#AddHandler cgi-script .cgi

to

AddHandler cgi-script .cgi .pl

You'll also need to add "Options ExecCGI" to the directory that the AWStats Perl files are located. This can be done eiether in a virtualhost file or in the main httpd.conf file like so:

<Directory /usr/local/awstats/wwwroot/cgi-bin>
    Options ExecCGI
</Directory>

If you decided to only have .pl enabled as a cgi-script for AWStats, then the above directory block should look like this instead:

<Directory /usr/local/awstats/wwwroot/cgi-bin>
    Options ExecCGI
    AddHandler cgi-script .pl
</Directory>

If you don't enable Options ExecCGI then you'll see something like this in your Apache error logs:

[Wed Sep 26 09:54:06 2007] [error] [client 10.1.1.232] Options ExecCGI is off in this directory: /usr/local/awstats/wwwroot/cgi-bin/awstats.pl

I use the GeoIP plugin to translate IP address to country codes, and was migrating a site from an old server to a new one. All the existing AWStats configuration and data files were copied over to the new server. However, when I went to view the stats in a web browser, I got the following error messages:

Error: Plugin load for plugin 'geoip' failed with return code: Error: Can't locate Geo/IP.pm in @INC
...
Error: Need Perl module Geo::IP or Geo::IP::PurePerl

How to install the Geo IP PurePerl plugin is covered in an earlier post. After installing it, I still got an error message like so:

Error: Plugin init for plugin 'geoip' failed with return code: Error opening /usr/share/GeoIP/GeoIP.dat at /usr/lib/perl5/site_perl/5.8.8/Geo/IP/PurePerl.pm line 59. (A module required by plugin might be missing).

This was easy enough to fix: the location of the GeoIP database on the new server was different from the old server. All the need to be changed was the location of the data file in the awstats configuration file. In my case, I just needed to change:

LoadPlugin="geoip GEOIP_STANDARD /usr/share/GeoIP/GeoIP.dat"

to

LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"

Now everything worked beautifully.




Comments