This guide explains how to set up mod_geoip with Apache2 on a CentOS 6 system. mod_geoip looks up the IP address of the client end user. This allows you to redirect or block users based on their country. You can also use this technology for your OpenX (formerly known as OpenAds or phpAdsNew) ad server to allow geo targeting.

2 Installing mod_geoip

Because mod_geoip is not available from the official CentOS repositories, we need to enable the EPEL repository:

rpm --import
rpm -ivh epel-release-6-7.noarch.rpm
yum install yum-priorities

Edit /etc/yum.repos.d/epel.repo…

vi /etc/yum.repos.d/epel.repo

… and add the line priority=10 to the [epel] section:

name=Extra Packages for Enterprise Linux 6 - $basearch

To install mod_geoip, we simply run:

yum install mod_geoip

You will then find the GeoIP database (GeoIP.dat) in the /usr/share/GeoIP directory. As the geographic allocation of IP addresses can change over time, it’s a good idea to download the newest GeoIP.dat now:

cd /usr/share/GeoIP/
mv GeoIP.dat GeoIP.dat_orig
wget -N -q
gunzip GeoIP.dat.gz

Next we restart Apache:

/etc/init.d/httpd restart

That’s it already!

Leave a Reply

Your email address will not be published. Required fields are marked *