Home » Cpanel/WHM » How To Install mod_geoip On a WHM/cPanel Server

How To Install mod_geoip On a WHM/cPanel Server

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

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 your web host to get the module installed for you (warning: don’t expect it to be easy).

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

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.

Originally posted 2016-02-16 22:27:25.

About admin

I have been working with Linux based systems since 2002. I hope the article published on this site will be useful to those new to server administration.
  • Andy

    Thank for the post.
    It worked fine for me with cPanel/WHM 11.40 on a CentOS 6.4 VPS.

    However, Step 3 needed the following corrections :-
    1) Remove the extra “wget” (you were just testing us, right!?)
    2) The file to download was at (probably due to cPanel Docs reorganisation) :-
    http://docs.cpanel.net/twiki/pub/EasyApache/EasyApacheCustomModules/custom_opt_mod-mod_geoip.tar.gz

    Hope the above helps.

    • Admin

      Thanks for reporting the update and error. I have updated the post.

  • John
    • Admin

      Thanks for the heads up. I have updated the post.

  • Nilands Place

    Date: 9/5/2015
    The URL for custom_opt_mod-mod_geoip.tar.gz is no longer valid. The wget got stuck and muffed my ModSecurity and I had to fix it before Apache would work! I downloaded and uploaded it! Try: [https://documentation.cpanel.net/display/EA/Custom+Modules?preview=/2326651/2326953/custom_opt_mod-mod_geoip.tar.gz] or [https://documentation.cpanel.net/display/EA/Custom+Modules] and look for it! It loads in a pop-up with some others to select. CSF did not work for the part where you must say yes in my CSF explorer plugin counsel, so I did it SSHD login and it went through OK!
    Also I found this: [https://forums.cpanel.net/threads/pecl-fails-for-geoip-install.493421/] if you have trouble installing the GeoIP PECL mod try with the -y (yes option) in yum. This was for my CentOS(6.7) cPanel/WHM VPS
    * Note: the PECL GeoIP will not find geoip so change the directory name to GeoIP 0775 [/usr/local/share/GeoIP]
    James Niland

  • Kamron Kennedy