Wednesday, October 19, 2011

mod_geoip2 with Apache2

Step 1:

Download the GeoIP C Library from MaxMind
Download http://geolite.maxmind.com/
Name : GeoIP.tar.gz

Extract the library:
#tar zxvf GeoIP.tar.gz

#cd GeoIP-1.4.6/

#./configure

# make

# make install

Step 2:

Download the GeoIP Apache2 API from the below URL
http://geolite.maxmind.com/download/geoip/api/mod_geoip2/mod_geoip2_1.2.5.tar.gz

# tar zxvf mod_geoip2_1.2.5.tar.gz

# cd mod_geoip2_1.2.5

Install the API

#apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c

# chmod 755 /usr/lib/httpd/modules/mod_geoip.so

[activating module `geoip' in /etc/httpd/conf/httpd.conf]

Step : 3

Download the latest GeoLite country database in binary format

# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

# gunzip GeoIP.dat.gz

# mkdir /usr/src/geo

# mv GeoIP.dat /usr/src/geo/

Step : 4

# vi /etc/httpd/conf/httpd.conf

Go all the way down to the end of file and add the following lines:


GeoIPEnable On
GeoIPDBFile /usr/src/geo/GeoIP.dat


Save it and exit

#service httpd restart

Now, its your mod_rewrite skills which can save you :)

Good Luck

or (If you are lazy)
wget http://203.130.201.244/centos/extras/5/i386/GeoIP-1.4.2-1.el5.i386.rpm
wget http://203.130.201.244/centos/extras/5/i386/mod_geoip-1.1.8-2.el5.i386.rpm
rpm -ivh GeoIP-1.4.2-1.el5.i386.rpm
rpm -ivh mod_geoip-1.1.8-2.el5.i386.rpm


/Pradyumna