I’m starting to use sphinx in my work, and wanted to get a solid development environment set up for it on my local OS X server. Since I built my local server with Mac Ports, it was actually pretty easy to get that installed:
sudo port install sphinx
However, I had trouble setting up the PHP extension for the Sphinx API. I could have used the sphinxapi.php that ships with the sphinx source code, but having a compiled extension is faster, and I don’t have to add more files to my php project. Installing Sphinx via Mac Ports didn’t help either, because it doesn’t install libsphinxclient, which is required to build the PHP Extension. That was until I found some instructions from someone doing something similar for Ruby.
Here are the steps I took to get the PHP extension up and running:
1. Download the latest sphinx source (0.98.1 as of this writing) from the Sphinx Search site, and uncompress the tarball.
2. Now compile libsphinxclient:
cd ./api/libsphinxclient
CXXCPP="gcc -E" ./configure --prefix=/opt/sphinx
make
sudo make install
3. Now download the latest sphinx client source (1.0.0 as of this writing) from the PECL site, and uncompress the tarball.
4. Now install the extension:
cd ./sphinx-1.0.0
phpize
./configure --with-sphinx=/opt/sphinx
make
sudo make install
5. Add the extension to php.ini and restart apache:
[sphinx]
extension=sphinx.so
6. Check to see if you’ve got it installed correctly. You should see sphinx support => enabled in the output:
php -i | grep sphinx
Now go rock the casbah and build a custom search engine with Sphinx Search!
Awesome! Thanks for the guide, this saved me a lot of trouble.
My Pleasure. It was a bit tricky to figure out so I had to blog it for me and others.
Thanks,
- Eric Marden
Your article was really helpful. Initially, I wasn’t able to compile the libsphinxclient because I used the sphinx source tarball downloaded by macports. After I downloaded the tarball from the sphinx website, all was well.