Install mod_geoip on cPanel with EasyApache 4
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.
Install mod_geoip on cPanel with EasyApache 4
Please login to the server via SSH and run the following commands:
yum install GeoIP GeoIP-devel GeoIP-data zlib-devel
Please check the directory /usr/share/GeoIP and verify the data files are there. If the data files are not there, please download them from MaxMind.
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz gunzip GeoIP.dat.gz wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz gunzip GeoLiteCity.dat.gz
Please install the following requirements.
yum install httpd-devel apr-devel ea-apache24-devel.x86_64 ea-apache24-tools.x86_64
Now compile the mod_geoip Apache module from source.
cd /usr/share/GeoIP wget https://github.com/maxmind/geoip-api-mod_geoip2/archive/1.2.10.tar.gz tar xvzf 1.2.10.tar.gz cd geoip-api-mod_geoip2-1.2.10/ sed s/remote_ip/client_ip/g -i mod_geoip.c apxs -i -a -L/usr/lib64 -I/usr/include -lGeoIP -c mod_geoip.c
Open the mod_geoip.conf file.
vim /etc/apache2/conf.modules.d/mod_geoip.conf
Add the following to it.
LoadModule geoip_module /usr/lib64/apache2/modules/mod_geoip.so <IfModule mod_geoip.c> GeoIPEnable On GeoIPDBFile /usr/share/GeoIP/GeoIP.dat Standard GeoIPDBFile /usr/share/GeoIP/GeoLiteCity.dat Standard </IfModule>
Restart Apache.
service httpd restart
Verify the installation using the following command.
httpd -M | grep geoip
Possible errors:
Error 1
If these packages “GeoIP, GeoIP-devel, GeoIP-data” are not available on yum, you need to install EPEL repository on the server.
yum install epel-release
Now run the following command again.
yum install GeoIP GeoIP-devel GeoIP-data zlib-devel
Error 2
You may get the following error while running “yum install httpd-devel apr-devel ea-apache24-devel.x86_64 ea-apache24-tools.x86_64”
Transaction Check Error: file /usr/share/aclocal/find_apr.m4 conflicts between attempted installs of ea-apr-devel-1.5.2-3.3.2.cpanel.x86_64 and apr-devel-1.3.9-5.el6_2.x86_64
You can sorted it by removing apr-devel
yum remove apr-devel
Now run:
yum install httpd-devel ea-apache24-devel.x86_64 ea-apache24-tools.x86_64
Install geoip PHP module
PHP 5.4
Install geoip php module using the following command:
/opt/cpanel/ea-php54/root/usr/bin/pecl install geoip
Check the PHP module is enabled using the following command:
/opt/cpanel/ea-php54/root/usr/bin/php -m | grep geoip
PHP 5.5
Install geoip module using pecl:
/opt/cpanel/ea-php55/root/usr/bin/pecl install geoip
Check the PHP module is enabled using the following command:
/opt/cpanel/ea-php55/root/usr/bin/php -m | grep geoip
PHP 5.6
Install geoip module using pecl:
/opt/cpanel/ea-php56/root/usr/bin/pecl install geoip
Check the PHP module is enabled using the following command:
/opt/cpanel/ea-php56/root/usr/bin/php -m | grep geoip
PHP 7.0
Install geoip php module using the following command:
/opt/cpanel/ea-php70/root/usr/bin/pecl install geoip
Check the PHP module is enabled using the following command:
/opt/cpanel/ea-php70/root/usr/bin/php -m | grep geoip
PHP 7.1
Install geoip php module using the following command:
/opt/cpanel/ea-php71/root/usr/bin/pecl install http://pecl.php.net/get/geoip-1.1.1.tgz
Check the PHP module is enabled using the following command:
/opt/cpanel/ea-php71/root/usr/bin/php -m | grep geoip
PHP 7.2
Install geoip php module using the following command:
/opt/cpanel/ea-php72/root/usr/bin/pecl install http://pecl.php.net/get/geoip-1.1.1.tgz
Check the PHP module is enabled using the following command:
/opt/cpanel/ea-php72/root/usr/bin/php -m | grep geoip
Also check how to install mod_geoip on cPanel with EasyApache3 from Here
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 info@grepitout.com
[…] mod_geoip Apache module help 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. Click Here […]
is it possible to block a country but allow a single IP from that country?
Can you also give an example for .access code?
need add path to .dat or not?
thank you in advance
Yes, it is possible to block all IP addresses of a country except one. You can use the following .htaccess code.
GeoIPEnable On
SetEnvIf GEOIP_COUNTRY_CODE US DenyCountry
Deny from env=DenyCountry
#Allow a specific IP address from the country you denied
Allow from IP-Address
Replace US with your desired Country. Check the country codes from the following link.
Country Codes
Also, replace with the IP-Address with the IP which you would like to allow.
now i have this problem, if someone visit my main page is blocked for example: http://www.mysite.com
but if he know a subpage for example: http://www.mysite.com/product.html then it is not blocked