Zhanhailiang Date: 2014-12-08
1. Install dependent Geoip-devel,geoip
geoip-devel.x86_64:development headers and libraries for geoipgeoip.x86_64: Library for 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 - Nhttp//Geolite.maxmind.com/Download/GeoIP/Database/Geolitecountry/GeoIP.dat.gzGunzipGeoIP.dat.gzMVGeoIP.dat/Usr/Local/Share/GeoIP/
wgethttp//Geolite.maxmind.com/Download/GeoIP/Database/GeoLiteCity.dat.gzGunzipGeoLiteCity.dat.gzmkdir - v /Usr/Share/GeoIPMV - vGeoLiteCity.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-geoip Make && 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]=>US[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.inchCommand Line code on line1Warning:geoip_region_by_name(): Required database not available at/Usr/Share/GeoIP/GeoIPRegion.dat.inchCommand Line code on line1
GeoIP PHP Extensions installation and configuration