Introduction
How can I install MaxMind GeoIP on my cPanel server?
Procedure
Please note:
- Maxmind mod_geoip is reaching End of Life May of 2022 and is not provided by cPanel.
- Maxmind is encouraging the use of the maxminddb_module instead of mod_geoip.
- There is no cPanel provided package or PHP modules for EA-PHP8 at this time.
- cPanel does not provide the maxminddb_module, mod_geoip module, or the database files.
It is possible to install the Apache modules for Maxmind GeoIP and Maxminddb as well as the database files and PHP modules for your cPanel server.
You will first need to register with MaxMind for an account in order to download the GeoLite2 free database. You can sign up here. MaxMind Geolite2
Installing geoipupdate
Next, we need to remove the old version of geoipupdate and install the newest version of the geoipupdate RPM. This will automatically update the databases. This can be found on the Maxmind GitHub page. https://github.com/maxmind/geoipupdate/releases
As of Jul 12, 2023, the latest release is 6.
First, verify the old RPM is present.
$ rpm -qa |grep geoipupdate
Then remove the RPM, replacing geoipupdate with the version that was returned from the previous command.
$ rpm -e --justdb --nodeps geoipupdate-2.5.0-1.el7.x86_64
Next, we install the newest version.
$ rpm -i https://github.com/maxmind/geoipupdate/releases/download/v6.0.0/geoipupdate_6.0.0_linux_amd64.rpm
After the install has completed, modify /etc/GeoIP.conf with the correct information for your account. You can find a preconfigured file here pre-filled configuration file, however, within the file, you do need to modify the YOUR_LICENSE_KEY_HERE
section with the key you previously generated in your MaxMind account. Save this information to /etc/GeoIP.conf
Finally to get the databases, run
$ geoipupdate
If you would like to automate the updates for the databases, add the following to the root cron.
16 11 * * 1,3 /usr/local/bin/geoipupdate
This will complete the installation for geoipupdate.
For the GeoIP PHP Modules:
To install GeoIP through yum and the GeoIP packages from Pecl.
$ yum install GeoIP GeoIP-devel
For PHP 5.4 through 5.6, replacing X with your version, you can run:
$ /usr/bin/ea-php5X-pecl install geoip
For 7 and above:
$ /usr/bin/ea-php7X-pecl install geoip-1.1.1
For the maxminddb PHP Modules:
For PHP 5.4 through 5.6, replacing X with your version, you can run:
$ /usr/bin/ea-php5X-pecl install maxminddb
For 7 and above:
$ /usr/bin/ea-php7X-pecl install maxminddb
For the Apache module and library:
You must first install ea-apache24-devel:
$ yum install ea-apache24-devel
Then, for the libmaxminddb library, https://github.com/maxmind/libmaxminddb
$ wget https://github.com/maxmind/libmaxminddb/releases/download/1.6.0/libmaxminddb-1.6.0.tar.gz
$ tar -xf libmaxminddb-1.6.0.tar.gz
$ cd libmaxminddb-1.6.0
$ ./configure
$ make
$ make check
$ make install
$ ldconfig
If after installing, you receive an error that libmaxminddb.so.0
is missing you may need to add the lib
directory in your prefix
to your library path. On most Linux distributions when using the default prefix (/usr/local
), you can do this by running the following commands:
$ sudo sh -c "echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf"
$ ldconfig
For mod_maxminddb:
https://github.com/maxmind/mod_maxminddb/
$ wget https://github.com/maxmind/mod_maxminddb/releases/download/1.2.0/mod_maxminddb-1.2.0.tar.gz
$ tar -xf mod_maxminddb-1.2.0.tar.gz
$ cd mod_maxminddb-1.2.0
$ ./configure
$ make install
For mod_geoip:
https://github.com/maxmind/geoip-api-mod_geoip2
$ wget https://github.com/maxmind/geoip-api-mod_geoip2/archive/refs/tags/1.2.10.zip
$ unzip 1.2.10.zip
$ cd geoip-api-mod_geoip2-1.2.10/
$ apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c
Verify the syntax is correct with $ httpd -t
, and if you receive Syntax OK
, then restart Apache.
$ /scripts/restartsrv_httpd