Get Started With IP2location Apache Module

Dependencies

This module requires IP2Location BIN database to function. You may download the BIN database at


Requirements

  1. IP2Location C API library.

  2. Apache 2.0x.

  3. GNU make or any compatible make utility.


Installation

You can install the IP2Location Apache Module in either Linux or Windows.

Linux

  1. Create a new folder called ip2location.

  2. Install the development libraries in Debian.

    apt install apache2-dev
    
  3. Download IP2Location C library from here into the ip2location folder.

  4. Decompress C library.

    unzip master.zip && rm master.zip
  5. Get into working directory.

    cd IP2Location-C-Library-master
  6. Compile and install IP2Location-C-Library.

    autoreconf -i -v --force
    ./configure
    make
    make install

    Note

    You may need to run ldconfig to refresh the shared libraries, if needed.

  7. Download IP2Location Apache Module into the ip2location folder.

  8. Decompress IP2Location Apache Module.

    unzip master.zip && rm master.zip
  9. Get into IP2Location Apache Module directory.

    cd ip2location-apache-master
  10. Compile the IP2Location Apache Module.

    apxs2 -i -a -L ../IP2Location-C-Library-master/libIP2Location/ -I ../IP2Location-C-Library-master/libIP2Location/ -l IP2Location -c mod_ip2location.c
  11. Run the below command and make sure you see IP2Location_module (shared) entry.

    apache2ctl -M
  12. Add following lines into /etc/apache2/apache2.conf.

    <IfModule mod_ip2location.c>
    	IP2LocationEnable On
    	IP2LocationDetectProxy <On|Off>
    	IP2LocationSetmode ALL
    	IP2LocationDBFile <ip2location_binary_db_file_with_fully_qualified_path>
    </IfModule>

Windows

  1. Create a new folder called ip2location.

  2. Download IP2Location C library from here into the ip2location folder.

  3. Decompress C library using 7-zip or other compression tools.

  4. Get into working directory.

    cd IP2Location-C-Library-master
  5. Start compilation.

    nmake /f Makefile.win
  6. Download and decompress Apache module into the ip2location folder.

  7. Navigate to ip2location-apache-master folder.

  8. Edit Makefile.win to change the path for C library.

    IP2LOCATION_CSRC_PATH = C:/ip2location/IP2Location-C-Library-master/libIP2Location
    IP2LOCATION_CLIB_PATH = C:/ip2location/IP2Location-C-Library-master/libIP2Location
    APACHE_INSTALL_PATH = "C:/Program Files/Apache Software Foundation/Apachex.x"
  9. Start compilation.

    nmake /f Makefile.win
  10. Copy IP2Location_apache.dll generated to the Apache modules directory.

  11. Add following lines into httpd.conf.

    <IfModule mod_ip2location.c>
    	IP2LocationEnable <ON|OFF>
    	IP2LocationDetectProxy <ON|OFF>
    	IP2LocationSetmode ALL
    	IP2LocationDBFile <ip2location_binary_db_file_with_fully_qualified_path>
    </IfModule>

Sample Codes

Apache .htaccess
RewriteEngine On
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^GB$
RewriteRule ^(.*)$ http://www.google.co.uk [L]
Apache Mod Security
SecRule ENV:IP2LOCATION_COUNTRY_SHORT "NG|VN" "deny,status:500,id:5000888,msg:'Block visitor from Nigeria and Vietnam'"

IP2Location Sample Database (BIN)

Sample Packages - BIN File IPv4 IPv6
IP2Location DB1 Download (1,001.91 kB) Download (1.04 MB)
IP2Location DB2 Download (24.58 MB) Download (25.22 MB)
IP2Location DB3 Download (21.21 MB) Download (21.32 MB)
IP2Location DB4 Download (43.89 MB) Download (44.04 MB)
IP2Location DB5 Download (31.89 MB) Download (32.05 MB)
IP2Location DB6 Download (54.08 MB) Download (54.26 MB)
IP2Location DB7 Download (48.70 MB) Download (48.88 MB)
IP2Location DB8 Download (59.17 MB) Download (59.37 MB)
IP2Location DB9 Download (36.78 MB) Download (36.95 MB)
IP2Location DB10 Download (64.62 MB) Download (64.89 MB)
IP2Location DB11 Download (37.51 MB) Download (37.69 MB)
IP2Location DB12 Download (65.32 MB) Download (65.55 MB)
IP2Location DB13 Download (35.03 MB) Download (35.21 MB)
IP2Location DB14 Download (66.55 MB) Download (66.80 MB)
IP2Location DB15 Download (40.72 MB) Download (40.96 MB)
IP2Location DB16 Download (70.89 MB) Download (71.18 MB)
IP2Location DB17 Download (42.47 MB) Download (42.69 MB)
IP2Location DB18 Download (78.33 MB) Download (78.61 MB)
IP2Location DB19 Download (61.85 MB) Download (62.09 MB)
IP2Location DB20 Download (80.79 MB) Download (81.12 MB)
IP2Location DB21 Download (44.39 MB) Download (44.56 MB)
IP2Location DB22 Download (84.78 MB) Download (85.22 MB)
IP2Location DB23 Download (62.33 MB) Download (62.51 MB)
IP2Location DB24 Download (85.90 MB) Download (86.40 MB)
IP2Location DB25 Download (87.92 MB) Download (88.33 MB)
IP2Location DB26 Download (94.51 MB) Download (95.09 MB)

Articles & Tutorials