GeoIP (Installation Guide from cPInstall)

The GeoIP extension allows you to find the location of an IP address. City, State, Country, Longitude, Latitude, and other information as all, such as ISP and connection type can be obtained with the help of GeoIP.

Installation Steps

For installing the said PHP extension as an APache module, You need to install the dependencies first.

yum install GeoIP GeoIP-devel GeoIP-data zlib-devel

Create a custom installation directory, from which you are going to install the mod_geoip2 package.

mkdir /usr/local/share/GeoIP

In the directory, download the latest Country and City database files from maxmind.

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
The files downloaded are GeoIP.dat.gz and GeoLiteCity.dat.gz. These files needed to be expanded or extracted as they are compressed for easy downloading. I used the below mentioned command for the same.
gunzip GeoIP.dat.gz
gunzip GeoLiteCity.dat.gz

For installing mod_geoip2, the dependencies httpd-devel and apr-devel needed to be installed.

The httpd-devel package contains the APXS (Apache Extension Tool) binary and other files that you need to build Dynamic Shared Objects (DSOs) for the Apache HTTP Server. If you are installing the Apache HTTP server and you want to be able to compile or develop additional modules for Apache, you need to install this package.

The apr-devel package provides the support files which can be used to build applications using the APR library. The mission of the Apache Portable Runtime (APR) is to provide a free library of C data structures and routines.

For installing the said dependencies, I used the following command :

yum install httpd-devel apr-devel

Since we have installed all the dependencies, lets proceed to the installation of the apache module mod_geoip.

For the same, we need to download the Package first.

wget http://www.filewatcher.com/m/mod_geoip2_1.2.5.tar.gz.11602-0.html

Extract the downloaded package.

tar xvzf mod_geoip2_1.2.5.tar.gz  
cd mod_geoip2_1.2.5

apxs is a tool for building and installing extension modules for the Apache web server. This is achieved by building a dynamic shared object (DSO) from one or more source or object files which then can be loaded into the Apache server under runtime via the LoadModule directive from mod_so.

I’ve used apxs command for building and installing the extension module mod_geoip. You can refer the link for the successful execution of the command.

apxs -i -a -L/usr/lib64 -I/usr/include -lGeoIP -c mod_geoip.c

Now we have to enable mod-geoip in your apache configuration. Otherwise it is not going to work. You’ll need the following lines in your httpd.conf file (/etc/httpd/conf/httpd.conf).

GeoIPEnable On
GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat Standard
GeoIPDBFile /usr/local/share/GeoIP/GeoLiteCity.dat Standard

Restart Apache so your changes will take effect by entering the following command.

/etc/init.d/httpd restart

You can check whether the installation is complete and the module mod_geoip is enabled or not just by creating a php info page.