Geoip

De SME Server Wiki

Geoip PHP references

http://php.net/manual/fr/ref.geoip.php

http://forum.webrankinfo.com/base-donnees-ville-t127000.html

http://blog.thecodingmachine.com/fr/content/installing-php-geolocalization-extension-centos

http://wiki.contribs.org/GeoIP


ajout des bases

cd / 
cd /var/lib/GeoIP 
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz


pour la db par ville

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
ln  GeoLiteCity.dat  GeoIPCity.dat

Faire un cron-job de mise a jour

mkdir -p /etc/e-smith/templates-custom/etc/crontab
echo "# Updating the GeoIP database monthly on the 5th at 0:00h.">/etc/e-smith/templates-custom/etc/crontab/91_Update_GeoIP_db
echo " 0 0 5 * * root /usr/bin/wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz -O /var/lib/GeoIP/GeoIP.dat.gz; /bin/gunzip -f /var/lib/GeoIP/GeoIP.dat.gz" >> /etc/e-smith/templates-custom/etc/crontab/91_Update_GeoIP_db
expand-template /etc/crontab


Geoip PHP instalaltion

L'extension geoip pour PHP est un module PECL. Le module PECL a comme dépendance la librairie geoip C qui doit être installée:

yum install GeoIP GeoIP-devel --enablerepo=extras

Si PECL, ou les dev php et httpd ne sont pas installés:

yum install php-pear php-devel httpd-devel libtool gcc-c++ re2c

(va installer en plus apr-devel, apr-util-devel, autoconf, automake, cyrus-sasl-devel, db4-devel, expat-devel, m4, openldap-devel, pcre-devel, libstdc++-devel)

Ensuite récupérez, compilez et installez le module:

pecl install geoip

Ajouter les infos pour que PHP charge l'extension en ajoutant la ligne suivante au fichier /etc/php.d/geoip.ini:

echo "extension=geoip.so" >> /etc/php.d/geoip.ini


Finalement, redémarrer Apache:

service httpd-e-smith restart

essais