Installing GeoIP for Apache2

Home / Coding / Installing GeoIP for Apache2

From time to time I need to install a way to accurately determine where users are located based on their header information. Thankfully there is a wonderful free database from MaxMind that gives you this ability when you install it with Apache2. Here are the steps to get it all setup on your Ubuntu (or other Linux) server.

Let’s get started! There are two different databases. One for country and one for local.

From the terminal:

cd /tmp/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip **

Now we’ve got a folder /tmp/ with two dat files – GeoIP.dat and GeoLiteCity.dat. Copy those over to this shared folder:

mkdir /usr/local/share/GeoIP/
cp ** /usr/local/share/GeoIP/

Next we need to install the Apache2 Module for using these databases.

sudo apt-get install libapache2-mod-geoip

And then we need to configure apache2 to actually use this module and those databases.

nano /etc/apache2/httpd.conf

In the httpd.conf add the following to the end of the file:

<IfModule mod_geoip.c>
# Activate the GeoIP module
GeoIPEnable On
# Specifies the location of the City database and specifies that
 # caching should not be performed
GeoIPDBFile /usr/local/share/GeoIP/GeoLiteCity.dat Standard
# Specifies the location of the Country database and that
 # caching should not be performed
GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat Standard
</IfModule>

Finally restart Apache2 and you’re good to go!

apache2ctl restart

Quesitions or problems? Leave a comment down below!

 

%d bloggers like this: