On several of my sites, I target visitors based on their GEO location. To be able to do this I have installed an Apache module called mod_maxminddb which is the former mod_geoip2.
Installation is fairly easy. Download and extract the latest tarball file from Github:
For instance, get release 1.1.0 as follows:
Then extract the file to a temporary folder as follows:
tar xvzf mod_maxminddb-1.1.0.tar.gz
The next step is to install the module, so first ‘CD’ into the extracted directory, then follow these steps:
./configure make install
The next step is to download the database and place it on your server. Again use wget and tar to do so, but first ‘CD’ to the proper directory where you want to store the mod_maxminddb database file:
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz tar xvzf GeoLite2-City.tar.gz
Finally, you have to enable it.
You can enable mod_maxminddb in your httpd.conf (/etc/httpd/conf/httpd.conf), in an include file such as httpd-phpmodules.conf (/etc/httpd/conf/extra/httpd-phpmodules.conf), or in an .htaccess file.
I personally prefer to put it in the include file. Here’s an example:
<IfModule mod_maxminddb.c> MaxMindDBEnable On MaxMindDBFile CITY_DB /usr/local/share/GeoIP/GeoLite2-City.mmdb MaxMindDBEnv MM_COUNTRY_CODE CITY_DB/country/iso_code MaxMindDBEnv MM_COUNTRY_NAME CITY_DB/country/names/en </IfModule>
And now that we got it all working, here’s a real-life example of a site using the mod_maxminddb module:
You can see the flags on several locations determining if a visitor can use a certain betting site or not, and displaying the right content in the right order to visitors.