php 的 sphinx 扩展安装依赖 libsphinxclient,该依赖安装在服务端安装程序中有,下载下载地址在这里,可以根据对应环境下载,我在这里下载的是 3.0.3 的 Linux x64 binaries。
sphinx-3.0.3-facc3fb-linux-amd64-glibc2.12.tar.gz
tar -zxvf sphinx-3.0.3-facc3fb-linux-amd64-glibc2.12.tar.gz
下载后解压,cd sphinx-3.0.3/api/libsphinxclient/ 进入依赖安装目录
./configure --prefix=/usr/local/sphinxclient
make
make install
安装完成
3、从 php 官网下载 sphinx 客户端地址 下载
sphinx-d958afb.tar.gz
cd sphinx-d958afb 解压进入目录
/usr/local/php70/bin/phpize
./configure --with-php-config=/usr/local/php70/bin/php-config --with-sphinx=/usr/local/sphinxclient
make
安装报错
In file included from /usr/include/php/20160303/main/php.h:414:0,
from /home/download/sphinx-339e123/sphinx.c:24:
/home/download/sphinx-339e123/sphinx.c: In function ‘zm_startup_sphinx’:
/home/download/sphinx-339e123/sphinx.c:1940:15: error: ‘SPH_RANK_PROXIMITY_BM25’ undeclared (first use in this function)
SPHINX_CONST(SPH_RANK_PROXIMITY_BM25);
^
/usr/include/php/20160303/Zend/zend_constants.h:42:105: note: in definition of macro ‘REGISTER_LONG_CONSTANT’
#define REGISTER_LONG_CONSTANT(name, lval, flags) zend_register_long_constant((name), sizeof(name)-1, (lval), (flags), module_nu
^
/home/download/sphinx-339e123/sphinx.c:1940:2: note: in expansion of macro ‘SPHINX_CONST’
SPHINX_CONST(SPH_RANK_PROXIMITY_BM25);
^
/home/download/sphinx-339e123/sphinx.c:1940:15: note: each undeclared identifier is reported only once for each function it appears in
SPHINX_CONST(SPH_RANK_PROXIMITY_BM25);
^
/usr/include/php/20160303/Zend/zend_constants.h:42:105: note: in definition of macro ‘REGISTER_LONG_CONSTANT’
#define REGISTER_LONG_CONSTANT(name, lval, flags) zend_register_long_constant((name), sizeof(name)-1, (lval), (flags), module_nu
^
/home/download/sphinx-339e123/sphinx.c:1940:2: note: in expansion of macro ‘SPHINX_CONST’
SPHINX_CONST(SPH_RANK_PROXIMITY_BM25);
^
/home/download/sphinx-339e123/sphinx.c:1941:15: error: ‘SPH_RANK_BM25’ undeclared (first use in this function)
SPHINX_CONST(SPH_RANK_BM25);
^
/usr/include/php/20160303/Zend/zend_constants.h:42:105: note: in definition of macro ‘REGISTER_LONG_CONSTANT’
#define REGISTER_LONG_CONSTANT(name, lval, flags) zend_register_long_constant((name), sizeof(name)-1, (lval), (flags), module_nu
^
/home/download/sphinx-339e123/sphinx.c:1941:2: note: in expansion of macro ‘SPHINX_CONST’
解决方案:
删除 sphinx.c里的SPH_RANK_PROXIMITY_BM25的报错函数重新编译成功。
/usr/local/bin/phpize
./configure --with-php-config=/usr/local/php70/bin/php-config --with-sphinx=/usr/local/sphinxclient
make && make install
到此成功完成php7 sphinx扩展的安装。