Installing the Geoip PECL package for Zend Server on OSX

Today I needed to get a client application up and running on my local system. This application uses the Geoip PECL package, so I needed to get this up and running. This turned out to be slightly more difficult than just a PECL install, as you're missing some libraries by default, so here is my log of things to do to get it up and running.

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?


Add comment

Comments

gravatar kataskeyi istoselidon: this is a very nice and helpful information. I am very happy to read this article
Κατασκευή Ιστοσελίδων
March 1, 2013
gravatar Ultrasound Gel: Very informative ! Thank for sharing.
April 8, 2013
gravatar Thank You Note After Second Interview: in case you don't have sufficient funds for the training program, there is a provision of scholarships and financial assistance for nursing students also. theres no need to wear a frumpy 2 fabric layer old-school nursing top in the middle of summer or ever. though persistent falls may be signs of elderly abuse and should be documented in the event a lawyer is ever needed.
May 15, 2013
gravatar glutathione spray: varicose veins sclerotherapy. things just have to run their course. dosage: 10 drops under the tongue, 3 times a day. however, i knew i had to go back into that room.
May 17, 2013

Php5_zce_logo

Tags

1337 2008 2010 2011 4developers access modifiers accessibility AdaLovelaceDay09 advent agavi agile alfred amsterdam amsterdamphp apache api apple article articles atk atkMetaNode audioscrobbler autoloading automation azure backwards compatibility barcelona barcodes bash bbc bbq beatstad belgium best practices bittorrent blogging blogs boards of canada book books bughuntday bundle caching cake cal evans calendar career cat cerf certificate cfp cilex clear cms cologne common sense communities community components composer conference conferences contest continuous integration contribute contribution crisis css curl custom d-day data migration datetime DbFinderPlugin decorator decorators deployment deps devdays development directoryindex directoryiterator docblox doctrine doctrine2 documentation download dpc dpc09 dpc10 dpc11 DPC2008 dreamhost drupal dv7 eclipse ed editors efficiency enterprise errors event events expertise ezcomponents facebook filter-branch filteriterator finland flickr fork framework frameworks free ticket freelance freeze frontend fun game games geoip germany getting real git github globiterator gnome-do google google calendar googletalk graceful degradation hack hackers hidden gem hiphop howto hp HR html http i386 ibuildings icann ide ideasofmarch idm imovie inclusivity indy ingewikkeld integration international php conference internet interview ipad IPC ipc ipc08 ipc10 ipc11se iterators iterm2 javascript jenkins jenkins-php job job openings jobeet john peel joomla joomladays kiva kubuntu launcher launchy left on the web libcurl libraries library lighttpd lime linktuesday linux live london loudblog m2ts mac magazines malware mambo manchester marjolein mediterra meeting meme meta methodology micro-financing microframework microsoft migration movie music mysql namespace namespaces netbeans netherlands newsfire nllgg northeastphp nos odmarco open source opinion ORM osx paradiso paris partnership pavilion pear pecl performance personal pfc10 pfc11 pfcongres pfcongrez pfz pfz.nl photo php PHP php5.3 phpabstract phpazure phpBB phpbb phpbelgium phpbenelux phpbnl10 phpday phpdoc phpdocumentor phpgg phpitalia phpnw phpnw08 phpnw11 phpnw12 phpstorm phptek phptek09 phpuk2009 phpUnderControl phpunit php|architect php|tek podcast politics portability postcrossing presentation presentations private projects protected prototype PSR-0 public python qa qr codes re2c recruiting refactoring review rewrite ruby on rails san francisco schedule scifi script security sensio seven things sexism sfdaycgn sflive2011 shell scripting silex simplexml slides smfony software sogeti solar sound speakers spl ssh standard standards star trek static steer strings stylesheets subversion symfony symfony live symfony2 Symfony2 symfonycamp symfonyday symfonylive symfonyUnderControlPlugin talk talks tech techademy technology techportal tek09 telecommuting terratec terrorism testfest testing textmate textpattern the right tool timeout tips tld todo tomas tools training twig uncon unet usability usergroup validation vhost video vim vinyl virus warp webinar weblogging webservices wiki windows winphp women wordpress work workshop world world of warcraft wpi writing wunderlist xml xpath xsd yara year youtube zc11 ZCE zemanta zend zend framework zend server zend studio zendcon Zend_Form zite
© 2004 - 2013 Stefan Koopmanschap + Powered by Symfony, photos powered by Flickr, links powered by Delicious, Shanghai smilies by Iconbuffet. Feeds: rss / atom. Left on the Web v4.4.0.1