Sphinx php 安装设置

首先下载 sphinx 最新版 2.2.11-release  http://sphinxsearch.com/downloads/release/

sphinx php扩展下载地址(目前已经支持php7):http://git.php.net/?p=pecl/search_engine/sphinx.git;a=shortlog;h=refs/heads/php7

scws下载地址:http://www.xunsearch.com/scws/download.php

scws词库下载地址:http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2

安装 sphinx

tar zxvf sphinx-2.2.11-release.tar.gz  
cd sphinx-2.2.11-release  
./configure --prefix=/usr/local/sphinx2 --with-mysql=/usr/local/mysql  
make && make install  

有可能会出现下面的错误

See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
Makefile:392: recipe for target 'sphinx.o' failed
make[2]: *** [sphinx.o] Error 4
make[2]: Leaving directory '/home/sphinx-2.2.11-release/src'
Makefile:244: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/sphinx-2.2.11-release/src'
Makefile:331: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

解决办法就是
修改 configure 文件把 #define USE_LIBICONV 0 最后的数值由1改为0 重新编译。

另外,编译过程中 512内存的机子如果内存不足的话会碰到

g++: internal compiler error: Killed (program cc1plus) 的报错。

安装 sphinx 客户端

cd api/libsphinxclient   //sphinx-2.2.11-release目录下  
./configure --prefix=/usr/local/sphinx2/libsphinxclient  
 make && make install

安装 sphinx php 扩展

 tar zxvf sphinx-339e123.tgz  
 cd sphinx-339e123 
 phpize  
 ./configure --with-sphinx=/usr/local/sphinx2/libsphinxclient --with-php-config=/usr/bin/php-config  
 make && make install

安装 scws

tar xvjf scws-1.2.3.tar.bz2  
# mkdir /usr/local/scws  
# cd scws-1.2.3  
# ./configure --prefix=/usr/local/scws/  
# make && make install

安装 scws php 扩展

# cd ./phpext/  
# phpize  
# ./configure --with-php-config=/usr/local/php/bin/php-config  
# make && make install

安装 scws 词库

# tar xvjf scws-dict-chs-utf8.tar.bz2 -C /usr/local/scws/etc/  
  
# chown www:www /usr/local/scws/etc/dict.utf8.xdb

配置 php.ini

# vim /usr/local/php/etc/php.ini  
[sphinx]  
extension = sphinx.so  
  
[scws]  
extension = scws.so  
scws.default.charset = utf-8  
scws.default.fpath = /usr/local/scws/etc

重启 php-fpm 即可完成安装