Sunday, March 18, 2012

Installing Sphinx 2.0.4 on Ubuntu 10.04 - Lucid

This blog post will help you install Sphinx 2.0.4 on Ubuntu 10.04. 

About Sphinx
Sphinx is a distributed search engine for full text searches. While MySQL offers its own storage engine (MyISAM) for full text searches but its not easy to scale it. Sphinx has many other advantages like: 
  • better indexing and searching speed 
  • good relevance search
  • and most importantly better scalability

Sphinx has two parts:
indexer - This part indexes the data source by pulling information from it and then builds indexes. 
searchd - This part serves search queries by looking up in the index created by the indexer.

Installing Sphinx
Following steps will help you install Sphinx successfully on your Ubuntu box: 
First check if the dependencies are already installed. If not install them.
sudo apt-get install libmysql++-dev libmysqlclient15-dev checkinstall
Download Sphinx 2.0.4 in '/tmp'
cd /tmp
sudo wget 
Unpack the 'tar.gz' file and install Sphinx 
sudo tar -xzf sphinx-2.0.4-release.tar.gz
The above command will unpack the 'tar.gz' file. You can find the contents in 'sphinx-2.0.4-release' directory
cd sphinx-2.0.4-release
Make install 
sudo ./configure
sudo make
sudo checkinstall

Note: You will be prompted to create a directory and set a description for the package. Also it will ask you some questions with default answers. Fill them as per your convenience.I had an error in package installation. On checking the log file I saw that specifying version was mandatory. So changed version to 2.0.4.

After installation, the package will be saved to: 

Make a new folder to keep the *.deb package:
sudo mkdir /home/[YOUR_USERNAME]/SphinxInstalls

Move the sphinx-2.0.4_2.0.4-1_i386.deb package from '/tmp/sphinx-2.0.4-release/sphinx-2.0.4_2.0.4-1_i386.deb' to '/home/[YOUR_USERNAME]/SphinxInstalls' 
sudo mv /tmp/sphinx-2.0.4-release/sphinx-2.0.4_2.0.4-1_i386.deb /home/[YOUR_USERNAME]/SphinxInstalls

You can now delete the working folder and the tar.gz file : 
sudo rm -r /tmp/sphinx-2.0.4-release
sudo rm /tmp/sphinx-2.0.4-release.tar.gz

Location of Configuration/Daemons/Documentation
You can find Sphinx Documentation in:
Sphinx Configurations are found in '/usr/local/etc/'. The configuration files that exists by default are:
Note: Default Sphinx configuration is sphinx.conf. It is not created by default. So you can copy 'sphinx.conf.dist' as 'sphinx.conf': 
sudo cp sphinx.conf.dist sphinx.conf 
Sphinx Processes (indexer, searchd etc.) are found in '/usr/local/bin/'.

To remove Sphinx: sudo dpkg -r sphinxsearch-2.0.4
To install again use the package in '/home/[YOUR_USERNAME]/SphinxInstalls': sudo dpkg -i sphinx-2.0.4_2.0.4-1_i386.deb 

You are done with the installation of Sphinx on your Ubuntu box. In my upcoming posts I will cover Sphinx configuration (configuring local indexes and distributed instances).
^^^^ Coming this weekend


  1. Really Nice Line by Line Tutorial.

    I was able to successfully install Sphinx using your tutorial.

    Only confusion that prevails is whether on Multiple Website VPS, should the sphinxInstalls folder be created for each separate user for each website or they all would be able to use the single instance of Sphinx for the entire VPS?

    1. Generally its recommended that Sphinx should be used as a separate instance but I do not think there will be any problem when multiple VPS access a single instance of Sphinx. I will be posting Sphinx configuration blog post shortly. That will clear all the confusion.

  2. For all enthusiasts, who would like the next steps, read this:

    From this URL, make sure that you don't use the first two commands:
    "sudo apt-get install sphinxsearch"
    "vi /etc/sphinxsearch/sphinx.conf"

    This would reinstall OLDER VERSION of Sphinx. Start by using the provided sample conf code into this file:
    you can use "pico /usr/local/etc/sphinx.conf" or "vi /usr/local/etc/sphinx.conf".

    I faced a problem when trying to run "sudo indexer test1" command with this result "
    FATAL: failed to open /var/lib/sphinxsearch/data/test1.spl: No such file or directory".

    The resolution is that you manually create the about said directory for test1.spl which will be created by the Indexer. Use the following Linux command:

    mkdir -p /var/lib/sphinxsearch/data/

    1. You are right Sheoran, you need to create the folders as Sphinx does not do that automatically for you. Thanks for mentioning it.


I appreciate your comments/feedback/questions. Please do not spam or advertise.