Are you interested for monthly server support with Unlimited tickets, 24×7 monitoring, Security Audit and lot more ? please check our Monthly server support plans

Block certain countries from accessing your web site:

You can block the access over certain countries to your website. This can be achieved by using the apache module Geo IP module.

This can be easily install and configure in your cPanel server. The main advantage of this module is the possibility of blocking various countries using the country code.

This is done by a module named mod_Geoip on the Apache. Below are the steps to enable and configure Geo IP on a cPanel servers,

Step 1.

First install binaries for GeoIP.

yum install GeoIP GeoIP-devel

Step 2.


Then you can download databases from MaxMind and put them into /opt/geoip/share/GeoIP/

Step 3.

Now install cPanel EasyApache GeoIP module. For that,

Run EasyApache and select mod GeoIP from


Step 4.

Configure GeoIP by adding to httpd configuration file [ you can also add this to httpd conf by editing  pre_virtualhost_global.conf from WHM]


LoadModule geoip_module modules/
<IfModule mod_geoip.c>
  GeoIPEnable On
  GeoIPDBFile /var/lib/GeoIP.dat

Step 5.

Now install GeoIP PHP Extension using the command below,

pecl install geoip

Step 6.

Restart Apache:


Now test if it is enabled by adding rules for that on .htaccess file on the public_html of the website. For that,

Edit the .htaccess file and add the following codes to it,


# Add more countries here
Deny from env=BlockThese

Here in the above code the country codes specified are,

AF and PK those belongs to countries AF Afghanistan and PK Pakistan.

You can see the list of all the country codes from the link below,

This is how to block the access of certain countries to your website.

Need our help to fix the issue ? Submit Support Ticket Now


[button size=”large” color=”green” title=”Server Administration Services from Stack Supports” link=””]View Server Administration Packages[/button]