Ubuntu in Production: Install Sphinx Search, with PHP(转载)

转载自: http://fideloper.com/production-ubuntu-install-sphinx-search

If you need or want a great full-text search engine, and you decide on Sphinx Search, here's how to install it on Ubuntu. I'm using 12.04 LTS Ubuntu Server.

This assumes two things:

  1. You want to use Sphinx Search
  2. You'll be searching the Sphinx index with PHP

Note: This is how I got it to work with PHP after a few hours of testing. There may be better ways (Installing it easy, getting PHP to work with it had a road-bump).

Installing

$ sudo apt-get install sphinxsearch

Well, that was easy. Sphinx is now installed. It's three main scripts are:

  • indexer - Indexes the data based on configuration file
  • searchd - Search daemon that runs in background
  • search - CLI tool to test searches

Next, getting PHP to work with it. This is the tricky part. Documentation says to use PEAR/PECL. Try that, and you'll get an ugly error:

$ sudo pear install pecl/sphinx
... lots of ugly output
... blah blah blah, missing libsphinxclient

We need libsphinxclient. This means going to the binary and building it using make/make install. But fear not, this is pretty easy - and there's no need to compile php.

From there, you can follow these instructions to make libspshinxclient and install the PECL library:

$ tar -xvf sphinx-2.0.6-release.tar.gz #You're version may differ
$ cd sphinx-2.0.6-release/api/libsphinxclient
$ ./configure
$ make
$ sudo make install

Now, this should work:

$ sudo pecl install sphinx
$ echo "extension=sphinx.so" >> /etc/php5/conf.d/sphinx.ini
$ sudo service apache2 restart

Here is a same PHP class, config file, and a simpler version of the instructions above for setting up Sphinx Search in Ubuntu.

Here's a Symfony 2 Sphinx Search package.

Here's an example of setting up Sphinx and searching with it.

猜你喜欢

转载自hongtoushizi.iteye.com/blog/1936943