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

[code lang=“bash”]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[/code]

[code lang=“bash”]kahwee:~ kahwee$ sudo pecl install geoip

…..done: 10,061 bytes

5 source files, building

…[/code]

If you get an error like the following:

[code lang=“bash”]…

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

…[/code]

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

[code lang=“bash”]yum install re2c geoip geoip-data geoip-devel[/code]

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

[code lang=“bash”]kahwee:~ kahwee$ sudo pecl install geoip

Build process completed successfully

You should add “extension=geoip.so” to php.ini[/code]

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

[code lang=“bash”]nano /etc/php.d/geoip.ini[/code]

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

[code lang=“bash”]extension=geoip.so[/code]

And finally to restart Apache:

[code lang=“bash”]/etc/init.d/httpd restart[/code]

So to summarize, here’s what I did:

[code lang=“bash”]sudo yum install re2c geoip geoip-data geoip-devel

sudo pecl install geoip[/code]

Remember to

[code lang=“bash”]/etc/init.d/httpd restart[/code]

This should work for Red Hat Linux too.

comments powered by Disqus