Note: I am using Zend Server Enterprise on my local machine. While I don’t think the steps will be different for Zend Server CE, you might want to check to make sure.

Starting out

When you try to just install the Geoip package using pecl install, the installation will fail. Initially, the errors might seem a bit cryptic, but if you look back a bit in the log of what the installation did, you’ll notice a couple of things. First thing is a missing ‘re2c’.

re2c

I simply downloaded the source package and compiled re2c using the simple commands:

./configure
make
sudo make install

This worked for me. Next time I tried pecl install geoip, the log shows it found re2c. BAM!

Geoip

The next error was slightly more cryptic:

checking for geoip files in default path... not found
configure: error: Please reinstall the geoip distribution

After some searching a bit of help from my current colleagues, I found out this refers to the MaxMind GeoIP API package. I downloaded the source for that, checked the README.OSX and found a nice shell script which will do most of the work for you. So I issued:

sh README.OSX
sudo make install

I got no errors at all during the installation, so I assumed the installation went fine. And indeed, running pecl install geoip now worked!

Enabling the extension

Last step left now is to enable the extension. Lazy as I am, I used the Zend Server control panel. I went to the Server Setup tab, to the extensions option. The listing now included the geoip extension. I clicked the “turn on” link, then “restart PHP” (whoever thought of the term “restart PHP” should seriously consider another carreer 😉 ). Unfortunately, “The system could not load this extension”.

Building for the right architecture

Trying to Google for this error, I didn’t really get much further. The error is too generic to really find any useful information. Asking around on Twitter, I luckily got some useful information that I could use in the search. Alvaro mentioned the files might not be built for the right architecture. Being on OSX Lion, I would assume everything was built for 64bit. And indeed, I could confirm this with:

file /usr/local/zend/lib/php_extensions/geoip.so 
/usr/local/zend/lib/php_extensions/geoip.so: Mach-O 64-bit bundle x86_64

Next step was to check whether Zend Server perhaps was not 64bit, and indeed, this was the case!

file /usr/local/zend/bin/php
/usr/local/zend/bin/php: Mach-O executable i386

So apparently, I had to build the geoip extension for i386 instead! Again, I had to ask around a bit to do this, and Jeroen hinted me to the CFLAGS. Of course, I had to use this both on the GeoIP API and on the PECL extension. So, I had to reissue the commands. Note: just rebuilding the Maxmind GeoIP API didn’t do the trick for me. I had to remove the directory and unpack the tgz again for this to work.

Before building the MaxMind GeoIP API, I opened the README.OSX file that contained the installscript. I updated it to be as follows:

export GEOIP_ARCH='-arch i386'
export MACOSX_DEPLOYMENT_TARGET=10.7
export LDFLAGS=$GEOIP_ARCH
export CFLAGS="-g -mmacosx-version-min=10.7 -isysroot /Developer/SDKs/MacOSX10.7.sdk $GEOIP_ARCH"
./configure --disable-dependency-tracking
perl -i.bak -pe'/^archive_cmds=/ and !/\bGEOIP_ARCH\b/ and s/-dynamiclib\b/-dynamiclib \\\$(GEOIP_ARCH)/' ./libtool
make

Not that I didn’t just change the GEOIP_ARCH, but I also updated the version numbers in the SDK line. Then I ran the script and ran make install.

Reinstalling the PECL extension

Then I uninstalled the PECL geoip package to remove the old version:

sudo pecl uninstall geoip

After doing that, I reinstalled the package again, but specifying i386:

sudo CFLAGS="-arch i386" bin/pecl install geoip

I then restarted Apache, refreshed the extensions page in the Zend Server control panel, and lo and behold: It said the extension was loaded and ready to use. Then I ran the script I needed to work on, and it didn’t error out anymore on the geoip functions missing. It worked!

One thing to note

In the above, for all PECL commands I did, I used the PECL binary in /usr/local/zend/bin/pecl. It is important to use this version if you’re using Zend Server, because it is the same build as the other stuff, with the right configuration. I don’t know if it would work with another PECL installation, but better be safe, right?


Leave a Reply

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