This guide explains how to set up mod_geoip with Apache2 on a Debian Squeeze 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 for advertising purposes
To install mod_geoip, we simply run:
apt-get install libapache2-mod-geoip
Then we open /etc/apache2/mods-available/geoip.conf and uncomment the GeoIPDBFile line so that the file looks as follows:
<IfModule mod_geoip.c> GeoIPEnable On GeoIPDBFile /usr/share/GeoIP/GeoIP.dat </IfModule>
Now restart apache to see the configuration changes in action.
A simple test to see if it works, create a php file:
Insert the following content and save the file:
<html> <body> <?php $country_name = apache_note("GEOIP_COUNTRY_NAME"); print "Country: " . $country_name; ?> </body> </html>
Now go to http://www.yourdomain.com/test.php and see the result !