How to install PHP GeoIP in Ubuntu

This instructions will install GeoIP over Ubuntu. It is tested over Ubuntu 12.04 LTS.

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

kahwee:~ kahwee$ sudo pear update-channels
Updating channel "doc.php.net"
Channel "doc.php.net" is up to date
Updating channel "pear.php.net"
Channel "pear.php.net" is up to date
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date

kahwee:~ kahwee$ sudo pecl install geoip
.....done: 10,061 bytes
5 source files, building
...

If you get an error like the following:

...
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for geoip support... yes, shared
checking for geoip files in default path... not found
configure: error: Please reinstall the geoip distribution
ERROR: `/tmp/pear/temp/geoip/configure' failed
...

You might not have correctly installed geoip. Learn how to install and automate GeoIP updates on Linux.

After installing that, you should be able to successfully complete the PHP GeoIP installation:

kahwee:~ kahwee$ sudo pecl install geoip
...
Build process completed successfully
You should add "extension=geoip.so" to php.ini

Finally, you can add “extension=geoip.so” to your PHP’s configuration.

sudo nano /etc/php5/conf.d/geoip.ini

I also added the following settings in /etc/php5/conf.d/geoip.ini:

extension=geoip.so

And finally to restart Apache:

sudo service apache2 restart

This should work for Debian too.

One thought on “How to install PHP GeoIP in Ubuntu

  1. Joan Roque

    Thanks for your post…
    I had to do
    sudo apt-get install build-essential
    before
    sudo pecl install geoip

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>