码迷,mamicode.com
首页 > Web开发 > 详细

GeoIP PHP扩展安装与配置

时间:2014-12-08 02:06:06      阅读:402      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   color   os   sp   for   on   

1. 安装依赖GeoIP-devel,GeoIP

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.gz
gunzip GeoIP.dat.gz
mv GeoIP.dat /usr/local/share/GeoIP/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
mkdir -v /usr/share/GeoIP
mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat
参考:

 

3. 安装扩展

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. 测试

# /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,如下

# /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

GeoIP PHP扩展安装与配置

标签:style   http   io   ar   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/yuyanbian/p/4150256.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!