GeoIP PHP extension

12 Feb

Install GeoIP PHP Extension

Install GeoIP C API

Install the PHP extension

  • Install the PHP extension using the PECL repository
    • pecl install geoip
  • Configure php.ini
    • echo “” > /etc/php.d/geoip.ini
  • Restart Apache
    • service httpd restart

Install GeoIP Lite Database

  • Downlad the Binary version of the GeoLite City Database from
  • Extract the contents of the distribution
    • gunzip GeoLiteCity.dat.gz
  • Move the dat file to Linux standard shareable location
    • mkdir -p /usr/local/share/GeoIP
    • mv GeoLiteCity.dat /usr/local/share/GeoIP/GeoIPCity.dat

      {info:title=Make Note}

      • In the copy/move step above ensure that you copy to is named GeoIPCity.dat, otherwise the APIs will not find it.



Test the API

  • In your PHP code embed the following code:
$infos = geoip_db_get_all_info();
if (is_array($infos)) {
    echo '<pre>' . print_r($infos,TRUE) . '</pre>';

API reference



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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: