How to install PHP GeoIP in CentOS

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:

...
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for geoip support... yes, shared
checking for geoip files in default path... not found
configure: error: Please reinstall the geoip distribution
...

…it is because you do not have re2c library and MaxMind GeoIP. We can install that with yum:

yum install re2c geoip geoip-data geoip-devel

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.

nano /etc/php.d/geoip.ini

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

extension=geoip.so

And finally to restart Apache:

/etc/init.d/httpd restart

So to summarize, here’s what I did:

sudo yum install re2c geoip geoip-data geoip-devel
sudo pecl install geoip

Remember to

/etc/init.d/httpd restart

This should work for Red Hat Linux too.

One thought on “How to install PHP GeoIP in CentOS

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>