How to install mod_geoip in cPanel

install mod_geoip
install mod_geoip

Install mod_geoip in cPanel

mod_geoip Apache module helps you to find the location of the IP address of the website visitors. This post describes how to install mod_geoip in cPanel using EasyApache 3. If your cPanel server is using EasyApache 4, please click on the following button to get the tutorial to install mod_geoip: Here

Install mod_geoip

Please login to the server via SSH and run the following commands:

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

Then you need to download the GeoIP database.

gzip -d GeoIP.dat.gz

You have installed the GeoIP database now. Next step is to install custom mod_geoip module for cPanel.

cd /usr/local/src/
tar -C /var/cpanel/easy/apache/custom_opt_mods -xzf custom_opt_mod-mod_geoip.tar.gz

Rebuild Apache using EasyApache. You can find the mod_geoip module is listed on the “Short Options List


Install mod_geoip
Install mod_geoip


You need to load and enable mod_geoip once the Apache rebuild completed.

Please go to:

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

Add the following codes into the box:

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

Also, you can verify the module is installed properly on the server by using the following command.

root@server [~]# httpd -M | grep geoip
 geoip_module (shared)
root@server [~]#

Redirect a domain according to country IP address (.htaccess rule)

Add the following into your .htaccess file:

GeoIPEnable On

# Canada
RewriteEngine on

# India
RewriteEngine on
RewriteRule ^/?$ "http\:\/\/in\.domain\.com\/" [R=301,L]

RewriteEngine on
RewriteRule ^/?$ "http\:\/\/us\.domain\.com\/" [R=301,L]

Replace with your domain name in the .htaccess rule. Also, you can add more countries in the .htaccess file.

That’s it!

If you like this post and wish to receive more articles from us, please like our FB page: Grepitout

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.

For more details on our services, please drop us an E-mail at