I recently created Tera-WURFL Explorer to allow people to browse through the WURFL, search for devices and upload images to the WURFL images collection. I originally used MySQL’s FULLTEXT index to let people search for devices, but quickly realized that it did not suit my needs. The main problem was that it does not index words smaller than what is specified in my.cnf (ft_min_word_len), and if you want to change it, you need to change it server-wide. This was not a good option for a large virtual host setup since it would affect all the FULLTEXT indices on the server; also, if you do change it, you need to reindex every FULLTEXT column in every database to prevent data corruption.
I did some research on search engines and eventually settled on Sphinx – mainly because it has a cool name, but also because there are some big-name success stories from companies like Craigslist who switched to it and never looked back.
Here’s how I installed it on Ubuntu 9.10:
First, you need to install the dependencies and download sphinx, then extract the archive and make it:
cd /tmp
wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
tar -zxvf sphinx-0.9.9.tar.gz
cd sphinx-0.9.9
./configure --prefix=/usr/local/sphinx
make
make install
Now all the sphinx-related files are in /usr/local/sphinx.
Next, I created a system user and group called “sphinx”:
Note: on RedHat-like systems, you can use “adduser -r -n sphinx”
Now, I created an init script for it. I would recommend downloading my init.d script.
mv searchd /etc/init.d/
chown root:root /etc/init.d/searchd
chmod 755 /etc/init.d/searchd
This script adds the following functionality:
service searchd start
# Stop Sphinx
service searchd stop
# Check if Sphinx is running
service searchd status
# Reindex every Sphinx index (works while started or stopped)
service searchd reindex
Now we’ll add sphinx to the startup and use the config option to setup sphinx to run as the sphinx user:
service searchd config
Note: on RedHat-like systems you can use “chkconfig –add searchd”
Lastly, you need to configure sphinx. I would copy the default config file and edit that one:
You can follow along with the comments in the file, or jump on the documentation site and figure out what all the settings do.
Now everything is setup and should work properly!
If you followed my directions and put the tarball in /tmp, the sphinx PHP and Python APIs and some examples are in /tmp/sphinx-0.9.9/api/. You should put a copy of the PHP or Python API somewhere else on the system so you can use it from your applications.
To see my use of the Sphinx search engine, take a look at this site:
http://www.tera-wurfl.com/explore/browse/
« Tera-WURFL 2.1.0 Why can’t anything go faster than the speed of light? »


Well post, I will try your solution !!!
great post.. thanks for the instructions but especially for the startup service script, very helpful.
Hello,
I have installed sphinx on centos 5.5. I have added the searchd daemon as you recommended above. I am running centos 5.5 on a vbox in a bridge network. It is runing mysql on the same machine.
[root@newwiki SphinxSearch]# mysql -v
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 193
Server version: 5.0.77 Source distribution
Reading history-file /root/.mysql_history
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> exit
Writing history-file /root/.mysql_history
Bye
[root@newwiki SphinxSearch]# php -v
PHP 5.2.6 (cli) (built: May 13 2010 12:09:31)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
When i try to start searchd it fails
[root@newwiki SphinxSearch]# service searchd start
Starting searchd
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff
using config file ‘/usr/local/sphinx/etc/sphinx.conf’…
listening on 127.0.0.1:9312
listening on all interfaces, port=9312
[Tue Jul 12 10:45:40.554 2011] [27757] FATAL: listen() failed: Address already in use
Not sure why telnet doesnt work
[root@newwiki SphinxSearch]# telnet localhost 9312
Trying 127.0.0.1…
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host: Connection refused
Can you help me please
Something else is already listening on port 9312, that’s why you got “FATAL: listen() failed: Address already in use”. Use “netstat -apn | grep 9312″ to figure out what it is, then “kill PID” (replace PID with the PID from the netstat output) to kill that conflicting process.