GeoIPPHP extension installation and configuration
Author: zhanhailiang date:
1. install GeoIP-devel and GeoIP dependencies
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 the IP database GeoIP. dat, GeoLiteCity. dat
Wget-N http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gzgunzip GeoIP.dat.gz mv GeoIP. dat/usr/local/share/GeoIP/
Wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gzgunzip GeoLiteCity.dat.gz mkdir-v/usr/share/GeoIPmv-v GeoLiteCity. dat/usr/share/GeoIP/GeoIPCity. dat
Note: GeoIPRegion. dat is a paid service;
Refer:
Http://dev.maxmind.com/geoip/legacy/install/country/
Http://forum.directadmin.com/showthread.php? T = 43309
3. Install 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. test
[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] => United States [region] => CA [city] => Fremont [postal_code] => 94539 [latitude] => 37.51549911499 [longpolling] =>-121.8962020874 [dma_code] => 807 [area_code] => 510)
Note: Because GeoIPRegion. dat is not found locally, a Warning is reported when geoip_region_by_name is called, as shown below:
[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 not available at/usr/share/GeoIP/GeoIPRegion. dat. in Command line code on line 1