Locate your visitor using GeoIP

Geo location software is used to get the geographic location of visitor using IP address. You can determine country, organization and guess visitors location. This is useful for

  • Fraud detection
  • Geo marketing and ad serving
  • Target content
  • Spam fighting
  • And much more.

GeoIP is helpful for these purposes.

There are many ways to use it, but the most preferred way is to use it as an Apache module. If Apache on your server has been set up to load dynamic modules, then you wont have to recompile Apache again. An Apache module for GeoIP mod_geoip can be installed to provide this additional functionality.

mod_geoip is a Lighttpd module for fast ip/location lookups. In this tutorial you will learn about mod_geoip installation and php server side examples to determine visitors country.

Here is how you install GeoIP as apache module:-

1. Login to the server as root and create a new directory

mkdir /usr/local/geoip

cd /usr/local/geoip

2. Download and install library:

wget http://www.maxmind.com/download/geoip/api/c/GeoIP.tar.gz

tar xzfv GeoIP.tar.gz

cd GeoIP*

./configure

make

make check

make install

cd ..

3. Download and build Module:

mkdir mod_geoip

cd mod_geoip

wget http://www.maxmind.com/download/geoip/api/mod_geoip/mod_geoip_1.1.1.tar.gz

tar xzfv mod_geoip_1.1.1.tar.gz

cd mod_geoip_1.1.1

apxs -cia -I/usr/local/include -L/usr/local/lib -lGeoIP mod_geoip.c

4. Add /usr/local/lib as a loadable dynamic link:

edit /etc/ld.so.conf and add /usr/local/lib at the bottom so it looks like this:

/usr/kerberos/lib

/usr/lib/mysql

/usr/X11R6/lib

/usr/local/lib

Then execute /sbin/ldconfig /etc/ld.so.conf

5. Review httpd.conf . You should have seen a backup of the httpd.conf has been made when building the module as mod_geoip info has been inserted.

You’ll find 2 lines inserted about mod_geoip.

First one:

LoadModule geoip_module lib/apache/mod_geoip.so

change to

LoadModule geoip_module /usr/lib/apache/mod_geoip.so

Add below that line:

GeoIPEnable On

the the second line is OK … just move it to the AddModule section to keep httpd.conf pretty:)

AddModule mod_geoip.c

6. Go and restart Apache and you should not get any error.

service httpd restart

Leave a Reply