21 Jul

Tutorial: Installing Mod GeoIP on Cent OS 6 or 7

Oliver Krautscheid Jul 01, 2013
0 2090

A webmaster should know how to install Apache modules and recompile Apache using apxs. In this article, I will take a closer look at installing Mod GeoIP on CentOS 6

The Short Guide: If You Know The Terminal Well

If you don’t want to read all of my instructions and simply want to enter the code and be done with it, you can use this code and then for the last line follow my instructions at the very bottom

 cd /root/scripts/
wget http://www.maxmind.com/download/geoip/api/c/GeoIP-latest.tar.gz
tar -xzf GeoIP-latest.tar.gz
cd /root/scripts/GeoIP-*
make install
 cd /root/scripts/
wget http://www.maxmind.com/download/geoip/api/mod_geoip2/mod_geoip2-latest.tar.gz
tar -xzf mod_geoip2-*.tar.gz
cd /root/scripts/mod_geoip2_*
apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c
 cd /root/scripts/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip Geo*
follow steps at bottom

Step 1: Installing The C GeoMod API (Required)

Tip: If you know how to use Git, Maxmind provides a Git clone for the C Geo API here

1. Enter cd /root to go to the root directory

Opening Root Directory.png

2. Next we are going to download the latest tar archive that includes the C GeoIP script that we can use to compile


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

Download Geoip Via Wget.png

3. The next step is to untar the archive using the tar -xzf command – Enter

tar -xzf GeoIP-latest.tar.gz

4. Now we are changing directory to the extracted folder using

cd ./GeoIP-*

– make sure you’re in the /root/scripts folder or this won’t work


5. We will now run the


command to initiate the configuration on CentOS 6

Run Configure.png

6. Finally, complete the building process using


(hit Enter) and then enter “make install” to complete the installation

Compile Geoip C Api.png

7. If successful, it should say something like “leaving directory” at the end

Step 2: Installing The Actual Apache Module

1. Go back to the /root/scripts directory

2. Enter

wget http://www.maxmind.com/download/geoip/api/mod_geoip2/mod_geoip2-latest.tar.gz

Download Latest Mod Geoip2 Apache Module.png

3. To save time, I usually use wildcards when entering a command like tar -xzf, see below

Wildcard For Extracting Files On Centos6.png

4. Enter

cd ./mod_geoip2_*

(make sure you are in /root/scripts when performing this or it won’t work)

Cd Wildcard.png

5. Finally, let’s compile that Apache module:

Compile Mod Geoip Apache Module.png

6. It should now have activated the module in httpd.conf and you can start using it

Activating Module Geoip.png

Get The Geo Lite City Database And Start Using It

1. cd into one of your home directories e.g. /home/mycoolsite/public_html

2. Create a new directory called geo (enter mkdir geo)

3. Now enter

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

Creating Directory For Geolitecity Database.png

4. This is a gzip archive so let’s unzip it by entering gunzip Geo*

Gunzip Geolite City Database.png


cd /usr/local/apache/conf/

Opening Httpd Conf.png

6. Enter pico httpd.conf or use vi

7. Hit CTRL + W on your keyboard

8. Verify that your httpd.conf has the following paths at the top

Pre Main 2 Conf.png

9. Enter


10. Enter

pico pre_main_2.conf

11. 5 lines are required, make sure to wrap them in IfModule tags or you might end up crashing Apache when that module is not loaded

5 Lines To Enable Geoip Db File.png

GeoIPEnable On
GeoIPOutput All
GeoIPDBFile /home/site/public_html/geo/GeoLiteCity.dat

12. Hit CTRL + O to save and CTRL + X to exit. One the next line enter

service httpd restart

13. Let’s see if everything runs smoothly now

14. Copy and paste this code into a file called affiliate.php

$outbound ='http://www.amazon.com/gp/product/B0050SYILE/ref=as_li_ss_tl?ie=UTF8&tag=singl0e6-20&linkCode=as2&camp=217145&creative=399373&creativeASIN=B0050SYILE';
echo "hello";
header('location: '.$outbound);

15. Change US to your own country code – you can look up the full list of all country codes here

About Us

Webmaster .Net is your all-in-one resource for blogging tips, system administration guides, industry news and a growing community of webmasters.

Can't find something or want to tip us?Contact@webmaster.net

Bulls and Bears

Leave a Comment

Your email address will not be published.

Webmaster Tutorials, Wordpress
0 shares673 views

WordPress SQL Query: Select And Delete Posts Between Two Dates

Oliver Krautscheid - Apr 08, 2017

If you are wondering how to delete posts for a certain date, you will need to know how Wordpress stores…

Advertising and Ad Networks, Copywriting
0 shares810 views

15 Tips For Increasing Facebook Ads CTR – Full Guide [2017 Update]

Cam Connor - Mar 30, 2017

In this article, we'll talk a lot about how you can write quality text ads on Facebook Ads to get…

Webmaster Tutorials
0 shares1532 views

10 Steps To Configure Nginx For WordPress, Drop Varnish And Cut Your CPU Load By 50%

Oliver Krautscheid - Oct 10, 2016

Are you using Varnish on your Wordpress blog? Possibly the Varnish script by Unixy? Great! Get rid off it. Here's…

Follow Us And get latest news

© 2016 Webmaster.Net - Property of Peakstone Media Ltd. - All rights reserved. | Privacy Policy | DMCA | Contact Us | Advertise