Install mod_GeoIP2 on Apache2 in CentOS 7

geoip-centos

If you need to install the excellent mod_geoip2 extension for Apache2 then it can be done fairly painlessly. First off, we need to make sure that we have gcc installed:
[crayon-5b77ab35b08df989058737/]
 

If you don’t have it then you could ‘yum install gcc’, but I prefer to install all development tools because they include gcc anyway:
[crayon-5b77ab35b08e8156702380/]
 

Install the GeoIP development package
[crayon-5b77ab35b08e9060598949/]
 

Install mod_geoip2 by fetching the latest version with wget. To check the latest version, take a look here first:

https://github.com/maxmind/geoip-api-mod_geoip2/releases

 

I’m installing 1.2.10 here with this, but replace the code in lines 1, 2 and 3 here with their latest version:
[crayon-5b77ab35b08eb327939128/]
 

Now we use the apxs (Apache Extension Tool) to build our extension modules for Apache:
[crayon-5b77ab35b08ed155102401/]
 

If you haven’t got apxs then you’ll need to install httpd-devel.

Be aware that this overwrites httpd so backup your server in case this fails or you get strange results.
[crayon-5b77ab35b08ef701695603/]
 

If this fails with “Error: Nothing to do”, then it’s fairly common. You’ll probably find that /etc/yum.conf is blocking the installation. We can get around this by either editing the configuration file or typing:
[crayon-5b77ab35b08f0789082272/]
 

You should now have mod_geoip2 installed on your server!