How To Install And Configure Sphinx on Linux

For Debian-based systems, run the following commands:

user@localhost: ~ sudo apt update


user@localhost: ~ sudo apt upgrade

user@localhost: ~ sudo apt install

user@localhost: ~ sudo apt install sphinxsearch

For RedHat/CenoOS:

user@localhost: ~ sudo yum install -y postgresql-libs unixODBC

user@localhost: ~ cd /tmp

user@localhost: ~ wget

user@localhost: ~ sudo yum install -y ./sphinx-2.2.11-1.rhel7.x86_64.rpm

Security settings

We close access from the outside:In /etc/sphinxsearch/sphinx.conf write on all listen. CentOS is a directory /etc/sphinx/ Sphinx instead. Leave only: listen = (or any other desired address)

Index configuration

The index is configured individually for each project in the /etc/sphinxsearch/sphinx file.conf

Sphinx uses two concepts:

  • source – where to get the data.
  • index – index parameters.
  • Index is always tied to some source. Source can be inherited

Ideal to do so:

The source from which the other sources will be inherited. It will describe the parameters of connection to the database server. Source main_src


type = mysql

sql_host = localhost

sql_user = root



Source, which will determine the connection to a particular database

source <database_name> : main_src


sql_db = <database_name>

sql_query_pre = SET NAMES utf8

sql_query_pre = SET collation_connection = 'utf8_unicode_ci'


source, which determines the data source (here already applied to the structure of the database itself)

source <source_name> : <database_name>


sql_query_pre = SET @id := 0

sql_query = \

SELECT @id := @id + 1 as id, name, properties, price, description \

FROM products \

WHERE active = 1

sql_field_string = name

sql_field_string = properties

sql_attr_string = name

sql_attr_string = description

sql_attr_float = price


Define index based on the source

ndex <source_name>


source = <source_name>

path = /var/www/sphinxsearch/data/<source_name>

morphology = none #stem_enru, soundex, methaphone

min_infix_len = 2


For more customization you need to study the documentation to Sphinx:

To reindex the data

indexer -c /etc/sphinxsearch/sphinx.conf –rotate <source_name>

To configure a regular reindex

In the process of changing data in MySQL tables, you need to re-index them.

To do this, the indexer command from step 3 must be added to the crown with the frequency that suits you.

user@localhost: ~ sudo contab -e

0 */4 * * * indexer -c /etc/sphinxsearch/sphinx.conf –rotate <source_name>

Ideally, use real-time indexes, then the need for regular reindexing will disappear and you can not add a job to cronra

Was this article helpful?

Related Articles

Leave A Comment?