Installing mod_geoip for Apache2 On Debian Lenny

by admin on February 7, 2010 · 6 comments

in Apache, Debian, Tutorials, Web Servers

This Tutorial explains how to install mod_geoip for Apache2 On Debian Lenny .

We Assume That You Already Have Apache2 As Already Discussed Here


To install mod_geoip

apt-get install libapache2-mod-geoip

Then with your favourite editor open /etc/apache2/mods-available/geoip.conf
and uncomment GeoIPDBFile , so that it looks similar to

GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat

Next we restart Apache2

/etc/init.d/apache2 restart

Yeah ! you have installed mod_geoip.
for testing it we create a php file with the below code in it..

<html>
<head>
<title>Your Country</title>
<head>
<body>
<?
$country = getenv(GEOIP_COUNTRY_NAME);
echo "Your country : $country";
?>
</body>
</html>

You can see it in action Here




Uses :
1. Country Based Redirection :

<?php

$country_code = ( !empty( $_SERVER['GEOIP_COUNTRY_CODE'] ) ) ? $_SERVER['GEOIP_COUNTRY_CODE'] : 'IN';
header( 'Location: http://www.vpsgeek.info/country/'.strtolower( $country_code ).'/' );
exit;
?>

The Above Code Redirects the users based on their country to a respective directory created for that country users..

You can see it in action Here

It will redirect to wjunction.com/country/yourcountry/
its only for demo purpose !

2. Geo Targetted ads:
this code first detects the visitor’s country code, then using simple if else condition,it will echo out the required ads, you can edit it to your needs.

<?php
$country = getenv(GEOIP_COUNTRY_CODE);
if ($country=="US")
echo "USA ADS";
else
echo"hey ! no ads for you !";
?>

You can see it in action Here

{ 1 trackback }

Tweets that mention Installing mod_geoip for Apache2 On Debian Lenny | VPS Geek -- Topsy.com
April 25, 2010 at 2:25 am

{ 5 comments… read them below or add one }

scenekid February 7, 2010 at 11:25 am

thanks :D

admin February 9, 2010 at 2:29 pm

@ scenekid
you are welcome :)
thanks for commenting :D

Ben February 25, 2010 at 12:28 pm

wow

admin April 29, 2010 at 9:10 pm

uploaded the post with some uses of mod_geo_IP
we can also use this to block certain countries from visiting our websites .

TomPier May 6, 2010 at 8:43 pm

great post as usual!

Leave a Comment

Previous post:

Next post: