Installing the GeoIP Apache module

This module allows you to determine which country, region, city, postal code, area code the visitor is coming from.

1. Install the module

apt-get install libapache2-mod-geoip

2. Restart Apache

/etc/init.d/apache2 restart

3. Create a new PHP file to test the module (pico /var/www/test.php or any file you can access on your server)

<?php
print_r($_SERVER);
?>

4. Navigate to the new file in a web browser (http://yourserver/test.php)

The response will be something like this:

Array
(
[GEOIP_COUNTRY_CODE] => GB
[GEOIP_COUNTRY_NAME] => United Kingdom
...
)

3 comments

  1. I’ve installed OK on Debian 2.6.18 and I’ve also uncommented the /etc/apache2/modules-available/geoip.conf line

    GeoIPDBFile /usr/share/GeoIP/GeoIP.dat

    which information elsewhere suggests is needed.

    However running a simple PHP test script produces the output

    Country name : N/A
    Country code : –

    So, either it really doesn’t know which country my IP is in (unlikely) or I’ve done something wrong. Anyone got any suggestions?

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>