How to install Sphinx on LINUX (ubuntu)

This is Raja, I use PHP for my web development. Recently, I had to install the search for "Sphinx" in my application with LINUX as OS.

I followed the instructions on this website.

http://www.howtoforge.com/how-to-install-sphinx-on-ubuntu-10.10

install sphinx on LINUX (Ubuntu), and I tested the application in the terminal, I got results similar to this

root@dev2 :/# search "test" Sphinx 0.9.9-release (r2117) Copyright (c) 2001-2009, Andrew Aksyonoff using config file '/etc/sphinxsearch/sphinx.conf'... index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec displaying matches: 1. document=1, weight=2, group_id=1, date_added=Thu Jan 5 18:18:55 2012 id=1 group_id=1 group_id2=5 date_added=2012-01-05 18:18:55 title=test one content=this is my test document number one. also checking search within phrases. 2. document=2, weight=2, group_id=1, date_added=Thu Jan 5 18:18:55 2012 id=2 group_id=1 group_id2=6 date_added=2012-01-05 18:18:55 title=test two content=this is my test document number two 3. document=4, weight=1, group_id=2, date_added=Thu Jan 5 18:18:55 2012 id=4 group_id=2 group_id2=8 date_added=2012-01-05 18:18:55 title=doc number four content=this is to test groups words: 1. 'test': 3 documents, 5 hits 

The problem is that I created a directory in the directory "/ var / www / sphinx_search", which contains the files sphinx.conf, sphinxapi.php and test.php.

code behind sphinx.conf

 source src1 { type = mysql sql_host = localhost sql_user = user sql_pass = pwd sql_db = test sql_port = 3306 # optional, default is 3306 sql_query = \ SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \ FROM documents sql_attr_uint = group_id sql_attr_timestamp = date_added sql_query_info = SELECT * FROM documents WHERE id=$id } index test1 { source = src1 path = /var/lib/sphinxsearch/data/test1 docinfo = extern charset_type = sbcs } indexer { mem_limit = 32M } searchd { port = 9312 log = /var/log/sphinxsearch/searchd.log query_log = /var/log/sphinxsearch/query.log read_timeout = 5 max_children = 30 pid_file = /var/run/searchd.pid max_matches = 1000 seamless_rotate = 1 preopen_indexes = 0 unlink_old = 1 } 

and the code test.php is

 require_once('sphinxapi.php'); //require_once('api/sphinxapi.php'); $s = new SphinxClient; $s->setServer("123.123.123.123", 9312); // NOT "localhost" under Windows 7! $s->setMatchMode(SPH_MATCH_EXTENDED2); $result = $s->Query("group"); echo '<pre>';print_r($result); 

when I try to run this application in a browser (http: // localhost / Raja / search_engine / sphinx /), this error is displayed.

 {"status":"failed","status_message":"connection to localhost:9312 failed (errno=10060, msg=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)"} 

As I am new to Sphinx, I cannot immediately understand this. Can anyone help me continue further.

Curiously looking for a solution before

Thanks, Advance, Raj.

+4
source share
2 answers

In your search example, you are using a search utility that does not need to run the searchd daemon. Therefore, the search is successful.

To use the sphinx API, you need to run the searchd daemon, for example:

 /path/to/searchd --config /etc/sphinxsearch/sphinx.conf 

If you installed sphinx using apt-get, try:

 searchd --config /etc/sphinxsearch/sphinx.conf 

After that, you can try the application in the browser.

But I do not understand this

 $s->setServer("123.123.123.123", 9312); // NOT "localhost" under Windows 7! 

You said that you are using sphinx under ubuntu, not Windows 7. Thus, the sphinx IP address should be the ubuntu IP host, not localhost.

BTW, ubuntu is sending an old version of Sphinx, I would recommend downloading the latest version from sphinxsearch.com. Latest version 2.0.3

+3
source

change your setServer () to this

 $s->SetServer('localhost', 'mysql_user_name', 'mysql_password', 3312); 

and set the port as 3312 in your sphinx.conf

 port = 3312 

I think this might work for you. If you don’t tell me what happened.

+2
source

Source: https://habr.com/ru/post/1391616/


All Articles