IP2Location Apache Module 8.0.0
This is a IP2Location Apache Module that enables the user to find the country, region, city, latitude, longitude, zip code, time zone, ISP, domain name, connection type, area code, weather, mobile network, elevation, usage type by IP address or hostname originates from. The library reads the geo location information from IP2Location BIN data file.
Supported IPv4 and IPv6 address.
For more details, please visit: https://www.ip2location.com/developers/apache
Requirements
- IP2Location C API library ( download from https://www.ip2location.com/developers/c )
- Apache 2.0x
- GNU make or any compatible make utility
Installation
Linux Build
Depending on installed Apache devel, APXS is either as "apxs" or "apxs2" available
- apxs -i -a -L<path_to_ip2location_c_api_compiled_library> -I<path_to_ip2location_c_api_src> -lIP2Location -c mod_ip2location.c e.g. apxs -i -a -L ../ip2location-c-8.0.0/libIP2Location/ -I ../ip2location-c-x.x.x/libIP2Location/ -l IP2Location -c mod_ip2location.c
Windows Build
- open Makefile.win and configure macros as below:
IP2LOCATION_CSRC_PATH = <path_to_ip2location_c_api_src>
e.g.IP2LOCATION_CSRC_PATH = ../C-IP2Location-x.x.x/libIP2Location
IP2LOCATION_CLIB_PATH = <path_to_ip2location_c_api_compiled_library>
e.g. IP2LOCATION_CLIB_PATH = ../C-IP2Location-x.x.x/libIP2Location
APACHE_INSTALL_PATH = <path_to_apache_installation>
e.g. APACHE_INSTALL_PATH = "C:/Program Files/Apache Group/Apache2"
- nmake /f Makefile.win
- copy the resulting IP2Location_apache.dll to Apache modules path
Apache Configuration
-
load the compiled IP2Location module by adding these lines in httpd.conf
LoadModule IP2Location_module <compiled_ip2location_dll_file_with_fully_qualified_path>
<IfModule mod_ip2location.c>
IP2LocationEnable <On|Off>
# ENV will set server variables
# NOTES will set apache notes
# ALL will set both
IP2LocationSetmode <ALL|ENV|NOTES>
IP2LocationDBFile <ip2location_binary_db_file_with_fully_qualified_path>
IP2LocationDetectProxy <On|Off>
</IfModule> -
restart Apache server to take effect of the changes
Notes If you are getting startup errors where Apache cannot locate the module files, please set your environment path as below:
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/apache2/modules/
$ export LD_LIBRARY_PATH
Testing
PHP Testing
from internet browser, load mod_ip2location_test.php
Apache Rewrite Testing
- add below lines to Apache configuration file httpd.conf:
RewriteEngine On
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^UK$
RewriteRule ^(.*)$ http://www.google.co.uk [L] - this will redirect all ip address from United Kingdom to http://www.google.co.uk
Sample BIN Databases
- Download free IP2Location LITE databases at https://lite.ip2location.com
- Download IP2Location sample databases at https://www.ip2location.com/developers
IPv4 BIN vs IPv6 BIN
- Use the IPv4 BIN file if you just need to query IPv4 addresses.
- Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.
Support
Email: support@ip2location.com.
URL: https://www.ip2location.com

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
