Home / Installing Geo IP PurePerl

Installing Geo IP PurePerl

I process logs on my webservers using AWStats, and use the GeoIP plugin to translate IP addresses into country codes. This article looks at how to install the Geo I PurePerl plugin, which is used by AWStats, and also how to download and install the Geo IP database files which are required by this plugin. The server I installed this onto was a CentOS 5 server, but the instructions here should work equally well on other Linux distributions.

Update March 17th 2009: I’ve updated the files in the command line examples below to the current versions as at the time of this update. Update note ends.

You should be able to install the Geo IP PurePerl package using cpan like so, but it never seemed to work for me:

$ cpan
cpan# install Geo::IP::PurePerl

So instead I needed to do it manually. Download and install Geo-IP-PurePerl, making sure you get the most recent version, using the following instructions. Below this initial set of instructions are a breakdown of the outputs of each command, and also how to install the GeoIP database if it is not already loaded.

$ wget http://search.cpan.org/CPAN/authors/id/B/BO/BORISZ/Geo-IP-PurePerl-1.23.tar.gz
$ tar -zxf Geo-IP-PurePerl-1.23.tar.gz
$ cd Geo-IP-PurePerl-1.23
$ perl Makefile.PL
$ make
$ make test
$ sudo make install

The output of perl Makefile.PL should look something like this:

$ perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for Geo::IP::PurePerl

The output of make should look something like this:

$ make
cp lib/Geo/IP/PurePerl.pm blib/lib/Geo/IP/PurePerl.pm
cp geoip-lookup blib/script/geoip-lookup
/usr/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/geoip-lookup
Manifying blib/man1/geoip-lookup.1
Manifying blib/man3/Geo::IP::PurePerl.3pm

If you don’t actually have the GeoIP database installed, make test will fail, and the resulting output will look something like this. Note the errors in bold.

$ make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/0_base..........ok
t/1_lookup........skipped
        all skipped: No GeoIP.dat found
t/2_namelookup....skipped
        all skipped: No GeoIP.dat found
All tests successful, 2 tests skipped.
Files=3, Tests=1,  1 wallclock secs ( 0.03 cusr +  0.25 csys =  0.28 CPU)

If this happens then you need to download and install the GeoIP database like so, either logged in as root or using sudo for each command (you may or may not need the GeoLiteCity database):

$ mkdir /usr/local/share/GeoIP
$ cd /usr/local/share/GeoIP
$ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
$ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
$ gunzip *

Now when you return to your Geo-IP-PurePerl-1.23 and run make test it should succeed, and the resulting output will look something like this:

PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/0_base..........ok
t/1_lookup........ok
t/2_namelookup....ok
All tests successful.
Files=3, Tests=31,  1 wallclock secs ( 0.09 cusr +  0.03 csys =  0.12 CPU)

Running sudo make install will output something like this:

$ sudo make install
Password:
Installing /usr/lib/perl5/site_perl/5.8.8/Geo/IP/PurePerl.pm
Installing /usr/share/man/man1/geoip-lookup.1
Installing /usr/share/man/man3/Geo::IP::PurePerl.3pm
Installing /usr/bin/geoip-lookup
Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Geo/IP/PurePerl/.packlist
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod

The Geo IP PurePerl package will now be installed.