您好,欢迎访问一九零五行业门户网

GeoIP PHP扩展安装与配置

作者:zhanhailiang 日期:2014-12-08
1. 安装依赖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. 配置ip数据库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
说明 :geoipregion.dat是付费服务;
参考:
http://dev.maxmind.com/geoip/legacy/install/country/
http://forum.directadmin.com/showthread.php?t=43309
3. 安装扩展
git clone git@github.com:billfeller/geoip.git; phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-geoipmake && make install
4. 测试
[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 [longitude] => -121.8962020874 [dma_code] => 807 [area_code] => 510)
注意,由于本地无geoipregion.dat,调用 geoip_region_by_name 时会报warning,如下
[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
其它类似信息

推荐信息