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
$trace_ip_addr = '18.104.22.168'; // 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 see how the GeoIP database is implemented using PHP which can be accessed via browser, click here.