Installing GeoIP database in Ubuntu 10.04

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

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

$trace_ip_addr = ‘’; // put any chosen IP address here
$geoinfo = geoip_record_by_name(”.$trace_ip_addr.”);
echo “Raw GeoIP information for:  $trace_ip_addr \n\n”;

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 test how a GeoIP database is implemented using PHP to be accessed via browser, click here.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s