本篇笔记记录了CentOS6.9编译安装Sphinx,编译安装php-sphinx扩展,并使用php7的sphinx扩展实现全文搜索的过程
nginx+mysql+php安装请参考以下笔记:
CentOS7源码编译安装nginx+php7.2+mysql5.7并使用systemctl管理
CentOS7yum安装nginx+php7+mysql
CentOS6.9源码编译安装nginx+php7+mysql环境
CentOS6.9yum安装nginx+php7+mysql环境
安装依赖
yum install wget gcc gcc-c++ automake autoconf expat expat-devel mysql-devel
进入源码存放目录,下载Sphinx
cd /usr/local/src/
wget -c http://sphinxsearch.com/files/sphinx-2.2.11-release.tar.gz
解压,编译,安装
tar zxvf sphinx-2.2.11-release.tar.gz
cd sphinx-2.2.11-release
./configure --prefix=/usr/local/sphinx --with-mysql --with-libexpat --enable-id64
make && make install
安装libsphinxclient,php扩展依赖
cd api/libsphinxclient
./configure --prefix=/usr/local/sphinx/libsphinxclient
make && make install
下载安装Sphinx的PHP扩展
php5
wget -c https://pecl.php.net/get/sphinx-1.3.3.tgz
tar zxvf sphinx-1.3.3.tgz
cd sphinx-1.3.3
php7
wget -c https://git.php.net/?p=pecl/search_engine/sphinx.git;a=snapshot;h=37594d5c4bf8da83880e1086f83735bd35ff5c5c;sf=tgz
tar zxvf sphinx-28afb06.tar.gz
cd sphinx-28afb06
编译安装
phpize
./configure --with-sphinx=/usr/local/sphinx/libsphinxclient/ --with-php-config=/usr/bin/php-config
make && make install
echo "[Sphinx]" >> /etc/php.ini
echo "extension = sphinx.so" >> /etc/php.ini
重启php-fpm
service php-fpm reload
创建测试数据
CREATE TABLE IF NOT EXISTS `product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商品数据表' AUTO_INCREMENT=1 ;
INSERT INTO `product` (`id`, `title`