无废话 Sphinx Server 2.0.1 及 Sphinx Client PHP 模块编译安装

Sphinx 又发新版本了,当前最新版本为 2.0.1。

Sphinx 安装
wget http://sphinxsearch.com/files/sphinx-2.0.1-beta.tar.gz
tar zxf sphinx-2.0.1-beta.tar.gz
cd sphinx-2.0.1-beta
./configure –prefix=/usr/local/sphinx –with-mysql
make && make install

PHP 的模块好久没有更新,只好先使用官方提供的 PHP 接口类(在源代码包的 api/ 目录下)。
实际使用中发现 PHP 模块有存在一些 BUG,建议大家还是使用官方提供的 PHP 接口类,而且在一些情况下,PHP 接口类性能并不比 PHP 模块的差。

— EOF —

无废话 Sphinx Server 及 Sphinx Client PHP 模块编译安装

Sphinx 安装
wget http://sphinxsearch.com/files/sphinx-1.10-beta.tar.gz
tar zxf sphinx-1.10-beta.tar.gz
cd sphinx-1.10-beta
./configure –prefix=/usr/local/sphinx –with-mysql
make && make install

libsphinxclient 安装(PHP模块需要)
cd api/libsphinxclient
./configure –prefix=/usr/local/sphinx
make 时会出现以下错误:

libsphinxclient # make
make  all-am
make[1]: Entering directory `/work/setup/sphinx-1.10-beta/api/libsphinxclient'
/bin/sh ./libtool --mode=compile --tag=CC gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -c -o sphinxclient.lo sphinxclient.c
mkdir .libs
 gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c sphinxclient.c  -fPIC -DPIC -o .libs/sphinxclient.o
sphinxclient.c: In function 'net_connect_get':
sphinxclient.c:1358: error: 'SO_NOSIGPIPE' undeclared (first use in this function)
sphinxclient.c:1358: error: (Each undeclared identifier is reported only once
sphinxclient.c:1358: error: for each function it appears in.)
make[1]: *** [sphinxclient.lo] Error 1
make[1]: Leaving directory `/work/setup/sphinx-1.10-beta/api/libsphinxclient'
make: *** [all] Error 2

请打开sphinxclient.c,将以下代码:

#ifndef _WIN32
        if ( setsockopt ( sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&optval, (sock
len_t)sizeof(optval) ) < 0 )
        {
                set_error ( client, "setsockopt() failed: %s", sock_error() );
                return -1;
        }
#endif

修改为:

#ifndef _WIN32
#ifdef SO_NOSIGPIPE
        if ( setsockopt ( sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&optval, (sock
len_t)sizeof(optval) ) < 0 )
        {
                set_error ( client, "setsockopt() failed: %s", sock_error() );
                return -1;
        }
#endif
#endif

如果出现以下错误:

gcc -g -O2 -o test test.o  .libs/libsphinxclient.a
.libs/libsphinxclient.a(sphinxclient.o): In function `set_error':
/opt/software/sphinx-1.10-beta/api/libsphinxclient/sphinxclient.c:359: undefined reference to `_vsnprintf'
collect2: ld returned 1 exit status
make[1]: *** [test] Error 1
make[1]: Leaving directory `/opt/software/sphinx-1.10-beta/api/libsphinxclient'
make: *** [all] Error 2

则注释掉头部的:

#define vsnprintf _vsnprintf

就可以了。

接着:
make install

Sphinx Client PHP 模块安装
wget http://pecl.php.net/get/sphinx-1.1.0.tgz
tar zxf sphinx-1.1.0.tgz
cd sphinx-1.1.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinx/
make && make install

更新:
Sphinx 2.0.1 版本的安装请看:
http://hily.me/blog/2011/05/sphinx-server-2-0-1-quick-installation/

-- EOF --