How to Install Mod_GeoIP for Apache in RHEL and CentOS

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

27 Responses

  1. Rishipal singh says:

    Dear ALL

    Above post not correct

    good tutorial, after installation It should be like that for blocking country

    SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry=1
    SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry=1
    Deny from env=BlockCountry

    Thanks
    Rishipal singh
    Eliresearch.com

  2. Rishipal singh says:

    Dear ALL

    good tutorial, after installation It should be like that for blocking country

    SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry=1
    SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry=1
    Deny from env=BlockCountry

    Thanks
    Rishipal singh

  3. Django says:

    resolved: You need to configure dynamic linker run time bindings as follows:
    # echo ‘/usr/local/lib’ > /etc/ld.so.conf.d/geoip.conf

    Run ldconfig to activate configuration:
    # ldconfig
    # ldconfig -v | less

  4. Django says:

    Hi,

    I am havin a problem http://xxx.com/testgeoip.php is givin a “500 internal server error”. i have an expired cpanel and whmcs in the my machine. pls help.

    Thank yu.

  5. Mahmoud says:

    Hi,
    Thank you for the tutorial,

    when I apply all the steps above, I can’t get the country, I only get the IP.
    I think there is some missing step for me.

    can you please help???

  6. Michael says:

    Hi,

    nice tutorial.
    I try u example and it show me the right land.
    But if i try to get the GEOIP_REGION or the CITY the result is empty.
    What reason could have. thanks for the help

    best regads
    michael

  7. leon says:

    why this simple code

    taken from here

    http://www.php.net/manual/en/function.geoip-org-by-name.php

    not working

  8. Rui says:

    I don’t code in PHP but when I was testing testgeoip.php script it only worked after I changed:
    <?
    to
    <?php

    Thanks for this step by step guide it has been really helpful, it is almost up and running. My only issue is that I get an error after changing the httpd.conf to add the country restriction to the server:
    "deny not allowed here"

    Any help would be appreciated,

    • Ravi Saive says:

      Use “IfModule” section to add. Use this way.

      <IfModule mod_geoip.c>
      GeoIPEnable On
      GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
      
      SetEnvIf GEOIP_COUNTRY_CODE AS AllowCountry
      
      Deny from all
      Allow from env=AllowCountry
      
      # Now allow specific IPs
      # Allow from 172.16.25.126
      
      </IfModule>
      
    • prasant rana says:

      Thanks Rui for mentioning it here.
      Absolutely, this is the change we have to make to get the country be shown on the screen with this script.

  9. Arnaud says:

    Just taking the time to say thank you for making this tutorial as clear as possible. It is a fantastic work!

  10. Lik says:

    Just wanted to share more elegant automatic GeoIP database update script which also grabs GeoLiteCity GeoLiteCountry/GeoIP asnum/GeoIPASNum GeoIPv6 free databases from the MaxMind site:

    http://forum.likg.org.ua/linux-specific/automatic-updates-for-maxmind-geoip-databases-t440.html

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.