How to compile and install sphinx search with PHP sphinx extension module on Mac Os X
I have said it already and ill say it again, i really dont like Mac. I cant figure out why some people insist its so cool.
Any way, as always i have to develop in different environment than run the live apps. I develop on mac and im using xamp as everyone else does in the team. From time to time we need some new module or some module is outdated or something and we have to compile stuff manually. Its real hassle.
Preparations
Check your php verson
php -v
Get sources of the same or similar version of php and unzip (i will use my paths here for consistency)
/Applications/xampp/xamppfiles/include/php/php5/
Copy the sources into the folder where xampp is setup so that you get Zend folder in this path:
/Applications/xampp/xamppfiles/include/php/php5/php/Zend/
Add path to pecl and other utils to your path in .profile (so that you can execute phpize etc from anywhere in the system)
export PATH=/Applications/xampp/xamppfiles/bin:/opt/local/bin:/opt/local/sbin:$PATH
Configuring PHP
Now you need to configure PHP so that further compilation works
cd /Applications/xampp/xamppfiles/include/php/php5/php/
./configure
Compilation of Sphinx c library
Get sphinx c library sources to compile module against them (currently 0.9.9). Problem is that i could not compile the PHP extension agains that version so i downloaded 0.9.8 which worked.
http://sphinxsearch.com/downloads.html
Unpack sphinx sources to any location (/Applications/xampp/xamppfiles/include/sphinx/)
cd /Applications/xampp/xamppfiles/include/sphinx/api/libsphinxclient
export LIBTOOLIZE=glibtoolize
chmod a+x buildconf.sh
./buildconf.sh
./configure
make install
I know, Pain!
At this stage make script should copy header files and library to default folders.
Compilation of PHP Sphinx extension
Unpack pecl sphinx module (anywhere)
cd /Users/aejsmont/sources/sphinx/sphinx-1.0.4
phpize
./configure --with-sphinx=/usr/local
make
Copy newly compiled module to php modules folder (for example)
cp /Users/aejsmont/sources/sphinx/sphinx-1.0.4/modules/sphinx.so \ /Applications/xampp/xamppfiles/lib/php/php5/extensions/no-debug-non-zts-20060613
Activate module in the php.ini
extension=sphinx.so
Why is it always so hard on mac? OMFG. Any way, it should let you connect to the search process now and query it.
Installing Sphinx from ports on mac
Install sphinx from ports
port install sphinx
Edit config file to connect to the db and run some query on tables (to index some data)
vim /Opt/local/etc/sphinx.conf
source src1
{
type = mysql
sql_host =localhost
sql_user =indexer
sql_pass =indexer
sql_db =sampledb
sql_port =3306
sql_sock =/Applications/xampp/xamppfiles/var/mysql/mysql.sock
sql_query =SELECT someid, sometext FROM object
sql_attr_uint = someid
sql_query_info = SELECT * FROM object WHERE id=$id
}
Starting up sphinx
Index the data from the database (will create sphinx index files)
indexer --config /opt/local/etc/sphinx.conf --all
Run the search deamon with console debugging (will not run in background)
searchd --console --config /opt/local/etc/sphinx.conf
PHP sphinx fulltext search example
Create sample php script testing the module and sphinx instance
$s = new SphinxClient();
$s->setServer("localhost", 3312);
$s->setMatchMode(SPH_MATCH_ANY);
$s->setMaxQueryTime(3);
$result = $s->query("Interview");
print_r( $result );
You should see connection on the console where sphinx is running
0.031 sec [any/0/rel 8 (0,20)] [*] Interview
You should also see some results.
Summary
It actually is quite a bit of hassle to compile the PHP sphinx module because you will need your PHP sources as well as the correct sphinx c client library and its header files.