Compiling Mod_Geoip2 for use with EasyApache 4 (EA4) and cPanel via command line (CLI)

We’ve recently switched to using Easy Apache 4 (EA4) on our cPanel installs as it’s ‘basically not beta’ now. And we ran into a problem where a site needed to have GeoIP installed but it wasn’t available to us through the WHM control panel.

After some extensive searching and trial and error, we were able to come up with instructions that worked for our particular install which I’ll document below incase someone else needs these.

Note, these assume you already have EasyApache 4 and php installed and configured — a working environment. 

Instructions for getting mod_geoip2 working on easyapache 4 (ea4)

  1. Step one login to your server. I personally just ‘su root’ instead of ‘sudo’ all the time, but I’m lady, and confident I won’t ‘rm -rf /lib’ or something equally as asinine.
  2. Now you’re going to want to issue this command;
    # yum install GeoIP GeoIP-devel GeoIP-data zlib-devel
  3. Then, we’re going to want to issue the following to create the GeoIP directory, and enter it
    # mkdir /usr/share/GeoIP && cd /usr/share/GeoIP
  4. Now we’ll want to grab the data files from MaxMind. These commands with download the city and country info.
    # wget
    # wget
    # gunzip GeoIP.dat.gz
    # gunzip GeoLiteCity.dat.gz
  5. Now we’re going to want to install some requirements for everything to build. If you already have something installed from this list it will just ignore it and install the rest.
    # yum install httpd-devel apr-devel ea-apache24-devel.x86_64 ea-apache24-tools.x86_64 wget nano
  6. You should still be in the same GeoIP directory but if you’re not just enter these commands to enter the directory you need to be in.
    cd /usr/share/GeoIP
  7. Now you’re going to want to grab the GeoIP source for apache module. Then, uncompress it, and, enter the directory.
    # tar xvzf mod_geoip2_1.2.5.tar.gz && cd mod_geoip2_1.2.5 
  8. Now we have to make a change due to apache 2.4 and some name changes, so, run this command now.
    # sed s/remote_ip/client_ip/g -i mod_geoip.c
  9. And finally we can go ahead and compile the module.
    # apxs -i -a -L/usr/lib64 -I/usr/include -lGeoIP -c mod_geoip.c
  10. Now we just have to modify the httpd.conf file for Apache to load the module
    # nano /etc/apache2/conf.modules.d/mod_geoip.conf
  11. Change the content of this file so instead of looking like this;
    LoadModule geoip_module       /usr/lib64/apache2/modules/

    instead, make sure it looks like this;

    LoadModule geoip_module /usr/lib64/apache2/modules/
    <IfModule mod_geoip.c>
    GeoIPEnable On
    GeoIPDBFile /usr/share/GeoIP/GeoIP.dat Standard
    GeoIPDBFile /usr/share/GeoIP/GeoLiteCity.dat Standard

    Then, exit and save the file.

  12. Now you’ll want to restart apache.
    # service httpd restart && apachectl restart
  13. Then you can go ahead and create an info file and check via the web if geoip is supported.
    # nano /var/www/info.php
  14. Put these contents in it
    <?php phpinfo(); ?>
  15. Close and exit the file, then visit your site at http://YOUR_DOMAIN.COM/info.php and you should see something similar to the following.geoip-easyapache4

  16. Congrats, you’re done!

Let me know if there’s any changes that need to be made to this or if this helped you in your quest to get mod_geoip2 working with cpanel/whm and easyapache 4 in the comments below!



  1. Hello, nice tutorial !!

    I get an error when I run the command:

    # apxs -i -a -L/usr/lib64 -I/usr/include -lGeoIP -c mod_geoip.c

    cannot open /usr/local/apache/build/ No such file or directory at /usr/bin/apxs line 217.

    I have edited the apxs file to change the line:

    my $installbuilddir = “/etc/apache2”;


    my $installbuilddir = “/home/cpeasyapache/src/httpd-2.4/build”

    But I get another error:

    sh: /usr/local/apache/bin/envvars: No such file or directory
    apxs:Error: Sorry, no shared object support for Apache.
    apxs:Error: available under your platform. Make sure.
    apxs:Error: the Apache module mod_so is compiled into.
    apxs:Error: your server binary `/usr/local/apache/bin/httpd’.

    I think that the apxs get the old values of Apache path. Any hint to solve that?


  2. Worked really well…. had a conflict with

    file /usr/share/aclocal/find_apr.m4 from install of ea-apr-devel-1.5.2-3.3.2.cpanel.x86_64 conflicts with file from package apr-devel-1.3.9-5.el6_2.x86_64

    Sorted it with

    # yum remove apr-devel

    Then ran

    # yum install ea-apache24-devel.x86_64 ea-apach24-tools.x86_64 wget nano

    Great tutorial.

    many Thanks

  3. I was used cloudlinux and I use compiled mod_geoip as below command.

    apxs -i -a -L/opt/geoip/lib/ -I/opt/geoip/include/ -lGeoIP -c mod_geoip.c


  4. Thanks, Matt.

    For those who it works to, there is an easier way without need of compiling.

    Just download the module from here:

    Then, untar it into this directory:

    And now, EasyApache 4 willl be displaying the new custom module for you from WHM. Just enable it.

    I found it here:

    And in here it is the same process, but running the EasyApache script from CLI at the end instead of doing it from WHM:

    Maybe you could add this easy solution at the beginning of your post.

  5. Oops! Sorry for my prior message.

    I shouldn’t have published it without having tested it before. I don’t want to confuse anyone.

    It’s not as easy as it seemed. It’s not running for me – EA4 is not showing the module.

    Finally, I had to compile it anyway 🙁

Add a Comment

Your email address will not be published. Required fields are marked *

Comment *
Name *
Email *