Installing GeoIP on cPanel Servers (Updated 2025)
GeoIP is a powerful extension that helps detect user location details, including country, city, latitude, longitude, and ISP. If you’re running a cPanel server, you can install GeoIP manually as an Apache module. This guide walks you through the latest installation steps.
Step 1: Install Required Dependencies
Before installing GeoIP, ensure you have the required libraries:
yum install GeoIP GeoIP-devel GeoIP-data zlib-devel
Step 2: Create a Directory for GeoIP Database Files
Next, create a custom installation directory for storing GeoIP database files:
mkdir -p /usr/local/share/GeoIP
Step 3: Download the Latest GeoIP Databases
MaxMind no longer offers free GeoLite databases via direct download. Instead, you need to sign up for an account and generate a license key:
- Sign up for a free MaxMind account: GeoLite2 Signup
- Generate a license key in your MaxMind account.
- Download the database using the following commands (replace
YOUR_LICENSE_KEY
with your actual MaxMind license key):
cd /usr/local/share/GeoIP
wget "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=YOUR_LICENSE_KEY&suffix=tar.gz" -O GeoLite2-Country.tar.gz
wget "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=YOUR_LICENSE_KEY&suffix=tar.gz" -O GeoLite2-City.tar.gz
Extract the database files:
tar -xvzf GeoLite2-Country.tar.gz --strip-components=1
tar -xvzf GeoLite2-City.tar.gz --strip-components=1
Step 4: Install Additional Dependencies
Install the necessary Apache and APR development packages:
yum install httpd-devel apr-devel
Step 5: Install the mod_geoip Apache Module
Download and extract the mod_geoip package:
cd /usr/local/src
wget https://github.com/maxmind/geoip-api-mod_geoip2/archive/refs/tags/1.2.10.tar.gz -O mod_geoip2.tar.gz
tar -xvzf mod_geoip2.tar.gz
cd geoip-api-mod_geoip2-1.2.10
Build and install the module using APXS:
apxs -i -a -L/usr/lib64 -I/usr/include -lGeoIP -c mod_geoip.c
Step 6: Configure Apache to Use GeoIP
Add the following lines to your Apache configuration file /etc/httpd/conf/httpd.conf
:
GeoIPEnable On
GeoIPDBFile /usr/local/share/GeoIP/GeoLite2-Country.mmdb
GeoIPDBFile /usr/local/share/GeoIP/GeoLite2-City.mmdb
Step 7: Restart Apache
Restart the Apache web server to apply the changes:
systemctl restart httpd
How to Verify GeoIP Installation
To check if the installation was successful, create a phpinfo.php
file:
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
Visit http://yourserver.com/phpinfo.php
and search for “geoip” to confirm that the module is enabled.
Need Help? @CustomerPanel Is Here for You
If you experience issues setting up GeoIP, our UnderHost Support team is available 24/7. We also offer dedicated servers with pre-installed GeoIP modules.