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.

comments powered by Disqus