php安装geoip,GeoIPPHP扩展安装与配置

作者: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.com"));'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

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值