How to install mod_geoip on cPanel

mod_geoip is an Apache module created by MaxMind. It’s widely used to geo-locate your visitors to know geographical location (country, city, IP lookup, etc). On this post today we will explore an easy way to install mod_geoip on cPanel servers.

Follow this step by step instructions on how to get mod_geoip installed on your cPanel/WHM server

How can I install mod_geoip on cPanel servers?

Login to your VPS / Cloud Hosting or Dedicated server as root (if you don’t have root, you must ask your web hosting provider to install this module for you)

1. Download, extract and install MaxMind GeoIP Database

mkdir /usr/share/GeoIP && cd /usr/share/GeoIP
gzip -d GeoIP.dat.gz

2. Install mod_geoip on cPanel

The following commmand will download and install mod_geoip for cPanel servers.

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

3. Recompile Apache to activate mod_geoip

For this we will use cPanel’s EasyApache script so this mod_geoip can become an active Apache module. Move to:

WHM >> Software >> EasyApache  >> Start customizing based on profile >> Activate / Check ‘Mod GeoIP’ >> then hit ‘Save and Build’.

That should start the apache compilation process to add mod_geoip to cPanel / WHM server.

4. Enable mod_geoip from Apache configuration

Now that Apache recompilation is done and that mod_geoip is an active apache module, now you need to enable mod_geoip for cPanel, as it’s there, but not enabled until you do it. Move to:

WHM >> Service Configuration >> Apache Configuration >> Include Editor >> Pre Main Include>> Select your current Apache version

Then copy and paste this details into your text area:

LoadModule geoip_module /usr/local/apache/modules/
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat MemoryCache

That’s all. At this time mod_geoip should be installe into cPanel and working as expected.

Install GeoIP PHP Extension

However, the story doesn’t finish here, now you need to install and add PHP GeoIP extension into your system. Run this command as root:

pecl install geoip

Then add this code to your php.ini file, usually located at /usr/local/lib/php.ini

Restart Apache to apply changes:

service httpd restart

How can I test PHP GeoIP is working?

You can test your GeoIP PHP module by running:

php -i |grep geo

The output should be something like:

php -i |grep geo
geoip support => enabled
geoip extension version => 1.0.7
geoip library version => 1004008
geoip.custom_directory => no value => no value

Important Note: at the time of writing this tutorial I didn’t knew there was a new MaxMind GeoIP module, you can find more about it here: Soon I will be releasing a new mod_maxminddb tutorial for cPanel servers, stay tuned.

About the Author: Santiago Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.


  1. Hello.

    It doesn’t work.


    –2017-05-06 18:40:40–
    Connecting to||:443… connected.
    HTTP request sent, awaiting response… 404 Not Found
    2017-05-06 18:40:41 ERROR 404: Not Found.

  2. Hello! I noticed that Maxmind has discontinued geolite DB ( and also recently removed the GeoLiteCountry/GeoIP.dat.gz file, therefore mod_geoip must be replaced with mod_maxminddb, since the format of even the IP db is different (now it is a file of type .mmdb instead of .dat),

    This article about mod_geoip is really useful, have you considered creating a new article for the installation and configuration of the new apache module for cpanel / whm? Since really so far there is no type of documentation about it.


Leave a Reply

Your email address will not be published. Required fields are marked *