Using Xapian on OS-X with MAMP

I just compiled and installed Xapian on my MacBook Pro (OS-X 10.6.6) using the instructions from the Xapian installation guide. The first time I compiled Xapian, everything looked ok, but when I tried to run the extension, it appeared to be compiled in the wrong OS Architecture (64-bit, which is the default for gcc aparently, while MAMP and its PHP5 version are compiled in 32-bit). So make sure you add the CXX='g++ -m32' option when you run ./configure. If you are not sure if the extension is built in 32-bit, just check by running

file xapian.so

on the resulting xapian.so file after the build, which should result in something like this :

$ file xapian.so
xapian.so: Mach-O bundle i386

Here’s the sequence for building the Xapian core and bindings (make sure you download and use the latest stable Xapian version) :

curl -O http://oligarchy.co.uk/xapian/1.1.4/xapian-core-1.1.4.tar.gz

curl -O http://oligarchy.co.uk/xapian/1.1.4/xapian-bindings-1.1.4.tar.gz

tar xvzf xapian-core-1.1.4.tar.gz

tar xvzf xapian-bindings-1.1.4.tar.gz

cd xapian-core-1.1.4

./configure CXX='g++ -m32'

make

sudo make install

cd ..

cd xapian-bindings-1.1.4

./configure CXX='g++ -m32' --with-php

make

sudo make install

cd ..

rm xapian-core-1.1.4.tar.gz

rm xapian-bindings-1.1.4.tar.gz

This will install the PHP bindings with the default OS-X Apache and PHP version, but as I am using MAMP for my development, I will need to perform some extra steps.

The xapian extension file for PHP is called xapian.so and is located in the directory xapian-bindings-1.2.5/php/.libs. Copy this file to the appropriate extensions folder of your MAMP installation (for me, this is /Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613 – this is specified in your php.ini file, look for ‘extension_dir ‘).

In the php.ini file (MAMP/conf/php5.2/php.ini), add the xapian extension by adding following line :

extension=xapian.so

For some reason, I also needed to copy all the files from xapian-bindings-1.2.5/php/.libs to the directory /usr/local/lib. If I didn’t do this, the extension would complain about ‘Symbol not found’.

Then restart your MAMP server to enable this extension.

Check phpinfo() to see if the extension is installed correctly. For some reason, the extension is only available in php5.3, not in 5.2 (at least on my Mac – might work for someone else). I might investigate some more, but for now php5.3 is enough to get me going :-)

*** Update ***
Since PHP5.3 is giving me some problems, I tried to use the extension in PHP5.2 again. Apparently the extension needs to be compiled using the header files of the correct php version. I tried to recompile the extension with following parameters

./configure --with-php  PHP_EXTENSION_DIR=/Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613 PHP_CONFIG=/Applications/MAMP/bin/php5.2/bin/php-config CXX='g++ -m32'

but then I get an error :

checking for zend.h... no
configure: error: '/Applications/MAMP/bin/php5.2/bin/php-config --includes' reports '-I/Applications/MAMP/bin/php5.2/include/php -I/Applications/MAMP/bin/php5.2/include/php/main -I/Applications/MAMP/bin/php5.2/include/php/TSRM -I/Applications/MAMP/bin/php5.2/include/php/Zend -I/Applications/MAMP/bin/php5.2/include/php/ext -I/Applications/MAMP/bin/php5.2/include/php/ext/date/lib' but zend.h can't be included from there

I tried copying the .h files from /usr/include/php/Zend to the correct location, but that doesn’t seem to change anything.

Next step : install php5.2 on my system including the headers and try compiling the extension using that version. So I installed the php5.2 version using the Entropy package. Then I changed the configure command to use this newly installed version (but still installing the extension to the MAMP extensions folder) :

./configure --with-php  PHP_EXTENSION_DIR=/Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613 PHP_CONFIG=/usr/local/php5/bin/php-config CXX='g++ -m32'

make

sudo make install

And it works ! Now I can finally go to sleep ;-)

Leave a Comment

NOTE - You can 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>

Trackbacks and Pingbacks: