How To Install mod_geoip On a WHM/cPanel Server

mod_geoip is an API module released by MaxMind for Apache to quickly and easily obtain your website visitors’ geographical information. It offers high performance IP lookup especially when used together with PHP.

While instructions to install mod_geoip on Linux with Apache are easily available on the Internet, not much is written on how to install the module on WHM/cPanel servers. This tutorial will walk you through installing mod_geoip on your WHM/cPanel step-by-step.

To be able to install mod_geoip on your WHM/cPanel server, you must have root access and is able to SSH to your Virtual Private Server (VPS) / Hyrbrid Server / Dedicated Server. Note that for Shared or Reseller hosting users, you may have to contact us to get the module installed for you (warning: we will need to schedule this).

Step 1: Log in to your VPS via SSH and create directory
Open up your SSH client (PuTTY) and log in to your VPS as root user. Then enter the following commands:

mkdir /usr/share/GeoIP
cd /usr/share/GeoIP

Step 2: Download and install GeoIP database
To download and install the GeoIP database provided by MaxMind, enter the following commands:

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gzip -d GeoIP.dat.gz 

Step 3: Download and install custom mod_geoip module for cPanel
Next we will install the custom mod_geoip cPanel module created by Sohail Riaz. Simply enter the following commands:

wget http://docs.cpanel.net/twiki/pub/EasyApache/EasyApacheCustomModules/custom_opt_mod-mod_geoip.tar.gz
tar -C /var/cpanel/easy/apache/custom_opt_mods -xzf custom_opt_mod-mod_geoip.tar.gz

Step 4: Rebuild Apache via EasyApache
Now 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

Step 5: 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 

Second, 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 

And that’s it! mod_geoip is now installed on your WHM/cPanel server in just 5 simple steps.

0 Shares:
Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like