Installing GeoIP database in Ubuntu 10.04

posted in: Computers | 0

These are the steps used to install free version of Maxmind GeoIP database which is used to get the location information of an Internet Protocol Address (IP Address) through a query using PHP.

Install geoip for php5 by using the command: sudo apt-get install php5-geoip
Restart apache2 server by using the command: sudo /usr/sbin/apache2ctl graceful

Next, getting the geoip database itself by issuing the command: wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

Further, it is needed to unzip the database by using the command: gunzip GeoLiteCity.dat.gz
Create a directory/folder to put the database: sudo mkdir -v /usr/share/GeoIP
Move the database to its position: sudo mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat

To use the installed geoip database, construct a simple PHP file (i.e., testgeoip.php) and copy the following codes and paste into the testgeoip.php

//content of testgeoip.php

<?php
$trace_ip_addr = '180.216.59.213'; // put any chosen IP address here
$geoinfo = geoip_record_by_name(''.$trace_ip_addr.'');
echo "Raw GeoIP information for:  $trace_ip_addr \n\n";
print_r($geoinfo);
?>

Run the file within the terminal by issuing the command: php testgeoip.php or put the file in www root folder of a web server and open it using a browser.

To see how the GeoIP database is implemented using PHP which can be accessed via browser, click here.

Ref: http://php.net/manual/en/geoip.setup.php