GeoIP PHP Extensions installation and configuration

Source: Internet
Author: User
Tags geoip maxmind
  Author: zhanhailiang Date: 2014-12-08

1. Install dependent Geoip-devel,geoip

Geoip-devel.x86_64:development headers and libraries for GeoIPGeoIP.x86_64:Library-country/city/organization to IP Address or hostname mapping
Yum Install geoip.x86_64 geoip-devel.x86_64

2. Configure IP Database Geoip.dat,geolitecity.dat

Wget-n Http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gzgunzip GEOIP.DAT.GZMV geoip.dat/usr/local/share/geoip/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gzgunzip geolitecity.dat.gzmkdir-v/usr/ Share/geoipmv-v Geolitecity.dat/usr/share/geoip/geoipcity.dat
Note: GeoIPRegion.dat is a paid service;

Reference:

  • http://dev.maxmind.com/geoip/legacy/install/country/

  • http://forum.directadmin.com/showthread.php?t=43309

  • 3. Install the extension

    git clone git@github.com:billfeller/geoip.git; Phpize./configure--with-php-config=/usr/local/php/bin/php-config--with-geoipmake && make install

    4. Testing

    [root@~/wade/pecllearning/geoip]#/usr/local/php/bin/php-r ' Print geoip_country_code3_by_name ("220.181.112.244"). Php_eol; ' chn[root@~/wade/pecllearning/geoip]#/usr/local/php/bin/php-r ' Print_r (geoip_record_by_name ("php.net")); ' Array (    [Continent_code] = NA    [Country_code] = = [    country_code3] = USA    [country_name] = > States    [Region] = + CA    [City] = Fremont    [Postal_Code] = 94539    [latitude] = = 37.51549911499    [Longitude] = -121.8962020874    [Dma_code] = 807    [Area_code] + 510)

    Note that because there is no GeoIPRegion.dat locally, the call to Geoip_region_by_name will be reported warning, as follows

    [root@~/wade/pecllearning/geoip]#/usr/local/php/bin/php-r ' Print geoip_region_by_name ("220.181.112.244"); ' PHP Warning:  geoip_region_by_name (): Required database not available at/usr/share/geoip/geoipregion.dat. In Command Line code on line 1 warning:geoip_region_by_name (): Required database is not available At/usr/share/geoip/geoipregi On.dat. Command line code on line 1
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.