web analytics

Blog

GeoIP and mod_geoip Installation on cPanel server

Tags: ApachecPanelgeoIPMod-geoIP

Published on: July 26, 2014 by Arun Kumar

GeoIP and mod_geoip Installation on cPanel server

Scenario:

GeoIP

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.Here we are providing the steps to install GeoIP and mod_geoip on a cPanel server

Installation Steps

For install GeoIP 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. 

geoip.png

 

Installation with WHM/cPanel

 After downloading the  GeoIP database, Download and install custom mod_geoip module for cPanel. The downloads are available in the webpage  https://documentation.cpanel.net/display/EA/Custom+Modules

#wget https://documentation.cpanel.net/download/attachments/2326651/custom_opt_mod-mod_geoip.tar.gz

# tar -C /var/cpanel/easy/apache/custom_opt_mods -xzf custom_opt_mod-mod_geoip.tar.gz

Rebuild Apache via EasyApacheNow that we have installed the GeoIP database and all the modules required to run mod_geoip with Apache and cPanel, we will need to rebuild Apache in WHM.

[WHM -> Software -> EasyApache (Apache Update) -> Start customizing based on profile ->

Check ‘Mod GeoIP‘ option (on Short / Exhaustive Options List page)

-> Save and Build

Load and enable mod_geoip

After Apache has been rebuilt with mod_geoip, we will need to load and enable the module every time Apache runs. First, in WHM, go to:

WHM -> Service Configuration -> Apache Configuration -> Include Editor -> Pre Main Include ->

Select the current Apache version

Enter the following codes into the textbox:

LoadModule geoip_module /usr/local/apache/modules/mod_geoip.so

GeoIPEnable On GeoIPDBFile /usr/share/GeoIP/GeoIP.dat MemoryCache

 Ah.. Finally the job is done. HURRAY

References:

Category : Apache, cPanel, Linux

Arun Kumar

Arun Kumar

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Get new updates

Categories

$0.000 items