To make GeoIP work on PHP ( all the functions in ), php5-geoip and GeoCityLite.dat must be installed. 

Some websites have wrong instructions advising you to download GeoCityLite.dat to /usr/share/GeoIP – wrong, it should be /usr/local/share/GeoIP 

# apt-get install php5-geoip
# mkdir /usr/local/share/GeoIP
# cd /usr/share/local/GeoIP
# wget
# gunzip GeoLiteCity.dat.gz
# service apache2 restart

It should work, from now on you should be able to use PHP Geo IP functions, be ware that if you test it from localhost, your IP will be 192.168…, upload your script to server first. 


$ip_address = $_SERVER['REMOTE_ADDR'];

echo"$ip_address, ";

$ip_country = geoip_country_code_by_name ($ip_address);



This should output your IP address and two-letter country code X.X.X.X, CC. See PHP manual for more functions like city or ISP.