Installing mod_geoip For Apache2 On Fedora 9

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2008-06-08 17:16. :: Fedora | Apache

Installing mod_geoip For Apache2 On Fedora 9

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 05/26/2008

This guide explains how to set up mod_geoip with Apache2 on a Fedora 9 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.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I'm assuming that you have a running Fedora 9 system with a working Apache2 + PHP, e.g. as shown in this tutorial: The Perfect Server - Fedora 9.

 

2 Installing mod_geoip

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 http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
gunzip GeoIP.dat.gz

Next we restart Apache:

/etc/init.d/httpd restart

That's it already!

 

3 A Short Test

To see if mod_geoip is working correctly, we can create a small PHP file in one of our web spaces (e.g. /var/www/html):

vi /var/www/html/geoiptest.php

<?php
print_r($_SERVER);
?>

Call that file in a browser, and it should display the SERVER array including values for GEOIP_COUNTRY_CODE, GEOIP_CONTINENT_CODE, and GEOIP_COUNTRY_NAME (make sure that you're calling the file from a public IP address, not a local one).

Array
(
    [GEOIP_CONTINENT_CODE] => EU
    [GEOIP_COUNTRY_CODE] => DE
    [GEOIP_COUNTRY_NAME] => Germany
    [HTTP_HOST] => 84.143.142.69
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
    [HTTP_ACCEPT] => text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
    [HTTP_ACCEPT_ENCODING] => gzip,deflate
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
    [HTTP_KEEP_ALIVE] => 300
    [HTTP_CONNECTION] => keep-alive
    [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
    [SERVER_SIGNATURE] => <address>Apache/2.2.8 (Fedora) Server at 84.143.142.69 Port 80</address>

    [SERVER_SOFTWARE] => Apache/2.2.8 (Fedora)
    [SERVER_NAME] => 84.143.142.69
    [SERVER_ADDR] => 192.168.0.100
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 84.143.142.69
    [DOCUMENT_ROOT] => /var/www/html
    [SERVER_ADMIN] => root@localhost
    [SCRIPT_FILENAME] => /var/www/html/geoiptest.php
    [REMOTE_PORT] => 57421
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] =>
    [REQUEST_URI] => /geoiptest.php
    [SCRIPT_NAME] => /geoiptest.php
    [PHP_SELF] => /geoiptest.php
    [REQUEST_TIME] => 1211819286
)

If you want to use Apache2 + mod_geoip for your OpenX ad server, make sure you select MaxMind mod_apache GeoIP under Settings > Main Settings > Geotargeting Settings:

 

4 Use Cases

You can use mod_geoip to redirect or block/allow users based on their country. You can find some useful examples for this here: http://www.maxmind.com/app/mod_geoip

 

5 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Haroon Ahmad (not registered) on Fri, 2009-01-16 13:40.
Hi

I am trying to install mod_geoip for apache 2.2.9 on centos 4.7, setup with whm and cpanel.

I first logged in as root user then did the following,

mkdir geoip

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 ..

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

now at this point i am getting following error
[code]
# apxs -cia -I/usr/local/include -L/usr/local/lib -lGoeIP mod_geoip.c
/bin/sh /usr/lib/apr/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -m32 -march=i386 -mtune=pentium4 -DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/apr-0 -I/usr/include/httpd -I/usr/local/include  -c -o mod_geoip.lo mod_geoip.c && touch mod_geoip.slo
/bin/sh /usr/lib/apr/build/libtool --silent --mode=link gcc -o mod_geoip.la  -L/usr/local/lib -lGoeIP -rpath /usr/lib/httpd/modules -module -avoid-version    mod_geoip.lo
/usr/bin/ld: cannot find -lGoeIP
collect2: ld returned 1 exit status
[b]apxs:Error: Command failed with rc=65536[/b][/code]


i was wondering if anybody could help with it.

thank you very much