在官方网站下载最新的sphinx,最近数据库要被搜索给玩死了,想想还是加个索引吧。这儿分享一下sphinx的安装及php扩展sphinx.so的安装方法,可能网上有很多相似的教程。
安装前请确定你安装了一些常用的东东,比如gcc mysql-devel之类的!当然,不装它也会提示你一些错误的,看着来吧!下面进入正题
sphinx官网:http://sphinxsearch.com/downloads/release/
请使用稳定版,线上机器就别玩beta版啦!
安装sphinx
tar?zxvf sphinx-2.2.11-release cd sphinx-2.2.11-release chmod +x configure ./configure?--prefix=/usr/local/sphinx?--with-mysql make?&&?make?install
在make时如果出现undefined reference to libiconv的错,请参考?sphinx编译安装出错:undefined reference to libiconv 解决?解决方法
解决: g++: internal compiler error: Killed (program cc1plus)
libsphinxclient 安装(PHP模块需要)
cd api/libsphinxclient chmod +x configure ./configure --prefix=/usr/local/sphinx make && make install
安装PHP的Sphinx模块
下载地址:http://pecl.php.net/package/sphinx
wget http://pecl.php.net/get/sphinx-1.3.3.tgz tar zxf sphinx-1.3.3.tgz cd sphinx-1.3.3 /usr/local/php/bin/phpize chmod +x configure ./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinx/ make && make install
/usr/local/php/bin/ ? ?这里PHP位置需要大家自行寻找,编译时进行替换即可。
修改php.ini (PATH 根据实际情况)
[sphinx] extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/sphinx.so"
编译完成后重启php进程,从phpinfo中看看是否有sphinx扩展。
安装好后,在安装目录下etc目录下,有份测试数据和配置的样本
cd?/usr/local/sphinx/etc cp?sphinx.conf.dist?sphinx.conf
将sphinx.conf里面的数据库地址,账号密码改下就好了,再将init.sql导进数据库btlet
测试执行
/usr/local/sphinx/bin/indexer -c sphinx.conf --all // 建立索引 /usr/local/sphinx/bin/searchd --config sphinx.conf // 启动sphinx
停止sphinx
/usr/local/sphinx/bin/searchd -c /usr/local/sphinx/etc/sphinx.conf --stop
就可以看到一些查询的相关信息了