linux install GeoIP for PHP

#1. download
wget http://www.maxmind.com/download/geoip/api/php/php-latest.tar.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

#2. gunzip the GeoLiteCity.dat.gz, move "GeoLiteCity.dat" to required path

#3. add GeoLiteCity's absolute path to params.json(keyname "geoLiteCityPath").

#3. gunzip php-latest.tar.gz, and rename the extract directory "geoip-api-php-1.13" to geoip, and then move the directory to .../UsherManager/protected/rotected/components/

#4. use geo_ip
require_once dirname(__FILE__).'/geoip/geoipcity.inc';
$ip = "123.125.114.144";
$gi = geoip_open(Yii::app()->params['geoLiteCityPath'],GEOIP_STANDARD);
$city = GeoIP_record_by_addr($gi, $ip);
geoip_close($gi);
return $city


a. wget http://download.maxmind.com/download/geoip/api/c/GeoIP-latest.tar.gz
tar zxvf GeoIP-latest.tar.gz
cd GeoIP-1.5.1/
./configure
make && make install

echo "include /usr/local/lib">>/etc/ld.so.conf
/sbin/ldconfig /etc/ld.so.conf

b. wget http://pecl.php.net/get/geoip-1.0.8.tgz
tar zxvf geoip-1.0.8.tgz
cd geoip-1.0.8
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-geoip
make
c. copy modules/geoip to php extension directory which is specified in php.ini, and add exteinsion=geoip.so to php.ini
d. wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip the GeoLiteCity.dat.gz, move the GeoLiteCity.dat to required path, and rename it to "GeoIPCity.dat".
e. add following to php.ini, then save
[geoip]
geoip.custom_directory=directory of "GeoIPCity.dat"
f. restart apache

posted on 2013-06-21 20:34  jmbkeyes  阅读(459)  评论(0)    收藏  举报

导航