How to setup GeoIP to track location of IP addresses

GeoIP is a PHP extension, which is used to get all the information like, city, state, country, longitude / latitude etc for any IP address. You can use this extension to track the visitors to your site. It can help you prepare better analytic for your user-base with the information collected.
To install GeoIP, we require the GeoIP C library version 1.4.0 or higher. If you are using ubuntu or Debian, simply run the following command :

gunzip GeoLiteCity.dat.gz
sudo mkdir -v /usr/share/GeoIP
sudo mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat
sudo apt-get install php5-geoip

To get the data for any IP or domain, you can use the following PHP functions :