Debian Tutorials

Debian Tutorials


Step by step tutorials showing you how to install and configure various applications and services on Debian based Linux distros.

March 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Categories


Installing the GeoIP Apache module

Ástþór IPÁstþór IP

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

Comments 3
  • Tárikly Lira
    Posted on

    Tárikly Lira Tárikly Lira

    Author

    Interesting, but is it possible to create a rule to restrict accesss by region or city?


  • aip
    Posted on

    aip aip

    Author

    Yes you can but you may require a license for that. Check the GeoIP Apache module web: http://www.maxmind.com/app/ip-location


  • Colin Foster
    Posted on

    Colin Foster Colin Foster

    Author

    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?