Sphinx and its configuration

The process of configuring Sphinx in a project, using Rocky Linux 9.x. as an example.

In other operating systems, the path to the Sphinx directory may be different.

  1. Install Sphinx on the server.

    The minimum recommended version is 3.4.1+

    It is assumed that indexing and the searchd daemon is running from the sphinx user.

  2. Connection parameters are specified in the /config/sys.php file

    'sphinx' => [
        'enabled' => true,
        'host'    => '127.0.0.1',
        'port'    => 9306,
        'path'    => '/var/lib/sphinx/',
        'version' => '3.4.1',
        'prefix'  => '',
    ],
    
  3. Run the console command to generate an up-to-date Sphinx configuration file.

    cd /path/to/project/public_html/
    php index.php bff=sphinx
    

    After that, an up-to-date configuration file /config/sphinx.conf will be generated for your project.

    This command needs to be executed again when accessing the database is changed.

  4. Copy the contents of the configuration file /config/sphinx.conf.global to the system configuration file for Sphinx /etc/sphinx/sphinx.conf

    In this file, specify the path to the /config/sphinx.conf file in your project in the files block, for example:

    files=(
         "/path/to/project/config/sphinx.conf"
    )
    
  5. Check the correctness of indexing by executing the command:

    indexer --config /etc/sphinx/sphinx.conf --all --rotate
    
  6. Start the searchd service and make sure it will automatically start after server reboot.

  7. Copy the script to index /config/sphinx_rotate.sh to /etc/sphinx/sphinx_rotate.sh and change permissions to allow execution.

    chmod +x /etc/sphinx/sphinx_rotate.sh
    

    The script may delete files in the /path/to/project/files/sphinx directory while running. Make sure that the sphinx user has write permissions to this directory.

  8. Set up a cron task to run for indexing, it is recommended to run from the sphinx user:

    */5 * * * * * * /etc/sphinx/sphinx_rotate.sh /path/to/project
    
  9. Enable the use of Sphinx in the relevant sections of "Site Settings / System Settings".