GeoIP PHP扩展安装与配置
发布于 2014-12-08 17:20:28 | 1630 次阅读 | 评论: 0 | 来源: PHPERZ
PHP开源脚本语言PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域。PHP的文件后缀名为php。
本文为大家讲解的是GeoIP PHP扩展安装与配置 的方法,geoip是国外的一个ip数据库,感兴趣的同学参考下。
1. 安装依赖GeoIP-devel,GeoIP
GeoIP-devel.x86_64 : Development headers and libraries for GeoIP
GeoIP.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.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
说明 :GeoIPRegion.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. 测试
[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
相关阅读:
GeoIP PHP扩展安装与配置
Windows下 Apache+Php的安装与配置方法
Windows IIS下PHP 5.2 安装与配置方法
Apache+php+mysql在windows下的安装与配置图解
windows下php环境配置PHP5 MySQL5 ZendOptimizer phpmyadmin安装与配置
Apache+php+mysql在windows下的安装与配置
php环境配置 php5 MySQL5 apache2 phpmyadmin安装与配置图文教程
php环境配置 php5 mysql5 apache2 phpmyadmin安装与配置
Gentoo 下安装与配置Nginx+ MySQL + PHP (fastcgi) 环境步骤分享
Windows下 PHP5和Apache的安装与配置
Linux下 php5 MySQL5 Apache2 phpMyAdmin ZendOptimizer安装与配置
Windows环境下PHP5和Apache的安装与配置