How to Install mod_geoip on a cPanel Server?

How to Install mod_geoip on a cPanel Server?

Mod_geoIP is an API module to obtain your website visitor’s geographical information. The module offers high-performance IP lookup, especially when used together with PHP. It is also used to block access for certain country IP access to the websites. The mod_geoip uses the libGEOIP library to look up geolocation information for a client as part of the http request process. This module takes effect either during request header parsing phase or the post read request phase, depending on whether it is configured for server-wide use or for a specific location/directory. Now let’s have a look at the integration process of mod_geoip.

1) Log in to the server via SSH as root.

# ssh root@IP

2) Before the installation, you have to clear the dependencies by installing the following binaries.

  # yum install GeoIP GeoIP-devel

 

3) GeoIP needs databases, you can download it from the following link.

http://geolite.maxmind.com/download/geoip/database/

4) Now install the cPanel EasyApache module;

# wget http://easyapache.cpanel.net/optmods/custom_opt_mod-mod_geoip.tar.gz

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

5) In most of the cPanel servers, GeoIP module will be already enabled. So if the module is already enabled you can ignore the steps 3 and 4

6) Run the script easy apache and select the mod_geoip.

# /scripts/easyapache GeoIP

 

7) Configure the GeoIP by adding the following entry to WHM >> Service Configuration >> Apache Configuration >> Include Editor >> Pre Virtual Host Include

LoadModule geoip_module modules/mod_geoip.so

<IfModule mod_geoip.c

GeoIPEnable On

GeoIPDBFile /var/lib/GeoIP.dat

</IfModule>

8) After the above process installs the GeoIP PHP extension from WHM >> Module installers, search for GeoIP and click on install.

 

9) After the installation of GeoIP php extension installation. Restart apache.

     # /scripts/restartsrv_apache

 

10) Finally, the installation of the module mod_geoip has been completed. Now you can block access to a particular website hosted on your server from a country by adding the below-mentioned entry to the .htaccess file. Open the .htaccess file with your favorite text editor.

# vi .htaccess

SetEnvIF GEOIP_COUNTRY_CODE CN BlockThese

SetEnvIF GEOIP_COUNTRY_CODE TR BlockThese

Enter the country code which you would like to prevent from visiting your site. Here I have used CN which denotes China and TR for Turkey.

If you need any further help please do reach our support department.

Was this answer helpful? 0 Users Found This Useful (0 Votes)