Getting around to writing a geo IP look-up script and needed to leverage maxmind’s geoip database. First things first, get the geoip lib installed and ready to go or else the dat file isn’t going to do me any good.
Initial Setup: First Try
At first I went with the PEAR route just because it wouldn’t require make installing’ing any dynamic PHP extensions (.so). Went to do a pear update-channels for the first time and got a boat load of eregi errors – off to a great start. Turns out CentOS 5.7 php53 (php 5.3.3) package w/ php-pear is not compatible – bastards! RedHat has an update available but is only available to their customers which doesn’t include me (since i go the free route of centos). Did some extra googling and found this: php-pear-1.4.9-8.el5.noarch.rpm.html (version 8.el5 versus centos 5.7’s native version 6.el5). Did a little wget magic followed by a yum install <path to package> and ta-da, no more eregi errors. Did a pear install Net_GeoIP and it worked too.
After all that hard work and fidgeting around, I read this little line on MaxMind’s website:
PHP Extension on PECL
Download a PHP extension that allows you to embed the GeoIP C Library inside PHP for improved performance. There is a new fork with a more complete implementation.
Crap! I love good performance and I’d take a compiled lib over an interpreted one any day. PEAR headache: all for naught. Proceeded with a pear uninstall Net_GeoIP, then cried for a half an hour since i just wasted 15 minutes (for a total of 45 man minutes wasted, yes).
Next stop, PECL.
Initial Setup: Second Try (start tl;dr)
- Started with a pecl update-channels, and all went well. That’s a first.
- pecl search geoip – got results, sweet.
- pecl install geoip… got through maybe 40 lines of the ./configure and it bombed, can’t find a valid compiler
- no worries, do a little yum groupinstall “Development Tools” and now I’ve got a C compiler (as well as automake and a few other required tools)
- pecl install geoip… configure bombs again, this time I’m missing the geoip linux packages, and at this point i’m thinking, “how many friggin dependencies are there?” holy overhead batman.
- yum install geoip-devel, wait, no,yum install GeoIP-devel since yum is case sensitive – this gets me everything i need.
- 3rd times a charm: pecl install geoip – install completes, tells me to add “extension=geoip.so” so I do like the robot I am, doing what a linux prompt tells me to do.
- service httpd restart – cycling apache allows for the geoip section to appear in the phpinfo() call, not sure why this is (more mysteries!)
OK, I got the libs installed and the commands are asking for me to call them.
Installing the MaxMind database
- mkdir /usr/share/geoip
- wget and extract geoip db to /usr/share/geoip (http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz)
- chmod -R 755 /usr/share/geoip
- nano /etc/php.ini
- add a [geoip] config section:
12 [geoip]geoip.custom_directory = /usr/share/geoip/
- service httpd restart
- check the phpinfo() for custom_directory
- https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=679121 / http://rhn.redhat.com/errata/RHBA-2011-1097.html