[精讚] [會員登入]
360

PHP for sphinx 函式庫安裝

PECL/sphinx PHP>= 5.2.2 已經能原生支援 sphinx,可是預設的沒有裝,我們得自己裝才能用

此文完整連結 http://n.sfs.tw/10059

複製連結 PHP for sphinx 函式庫安裝@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2017-07-31 10:34:39 最後編修
2016-10-23 01:57:11 By 瘦河馬
 

舊版本的php或系統可參考這篇,新版本的php可直接跳第五步驟用yum安裝

OS

CentOS release 6.5 (Final)
Linux 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

PHP
# php -v
PHP 5.3.3 (cli) (built: Sep 30 2014 05:55:00)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

一、使用PECL 安裝 sphinx套件

# pecl install sphinx
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pe
downloading sphinx-1.3.3.tgz ...
Starting to download sphinx-1.3.3.tgz (15,555 bytes)
......done: 15,555 bytes
....中略...

Can't find PHP headers in /usr/include/php
The php-devel package is required for use of this command.
ERROR: `phpize' failed

解決:安裝php-devel (可能是php55w-devel或php56w-devel)

# yum install php56w-devel

checking for libsphinxclient headers in default path... not found

configure: error: Cannot find libsphinxclient headers
ERROR: `/var/tmp/sphinx/configure --with-sphinx' failed

出錯,出現組態錯誤 Cannot find libsphinxclient headers

原來 libsphinxclient 要自己下載自己編[1],請看三、重新組態libsphinxclient headers

二、下載 sphinx 的原始碼

1. 到下載點[2]找到原始碼
# wget http://sphinxsearch.com/files/sphinx-2.3.1-beta.tar.gz

並解壓縮

2. 切換到目錄
# cd sphinx-2.3.1-beta/api/libsphinxclient

3. 執行
# sh ./buildconf.sh

configure.in:26: warning: macro `AM_PROG_LIBTOOL' not found in library
rebuilding configure

make: libtoolize: Command not found
make: *** [configure] Error 127

出錯,出現找不到 libtoolize的錯誤,這個錯誤要安裝 libtool來解決[3]

4. 安裝 libtool
# yum install libtool
...中略..
Installed:
  libtool.x86_64 0:2.2.6-15.5.el6

Complete!

三、重新組態libsphinxclient headers

# sh ./buildconf.sh
rebuilding configure
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: You should add the contents of the following files to `aclocal.m4':
libtoolize:   `/usr/share/aclocal/libtool.m4'
libtoolize:   `/usr/share/aclocal/ltoptions.m4'
libtoolize:   `/usr/share/aclocal/ltversion.m4'
libtoolize:   `/usr/share/aclocal/ltsugar.m4'
libtoolize:   `/usr/share/aclocal/lt~obsolete.m4'
libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.in and
libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
configure.in:20: error: possibly undefined macro: AC_PROG_LD
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.in:26: error: possibly undefined macro: AM_PROG_LIBTOOL
rebuilding sphinxclient_config.h.in
rebuilding Makefile.in files

Makefile.am:3: Libtool library used but `LIBTOOL' is undefined
Makefile.am:3:   The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
Makefile.am:3:   to `configure.in' and run `aclocal' and `autoconf' again.
Makefile.am:3:   If `AC_PROG_LIBTOOL' is in `configure.in', make sure
Makefile.am:3:   its definition is in aclocal's search path.
make: *** [makefiles] Error 1


出錯,出現Libtool library used but `LIBTOOL' is undefined的錯誤
這個問題很麻煩,試過[4]的文件,試了一堆上面的方法但沒解決問題 。最後看到這裡[5],有人提問,同時他自問自答,就是重新執行sh一次,竟然解決了。

# aclocal

# autoheader

# sh ./buildconf.sh
rebuilding configure
libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.in and
libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
rebuilding sphinxclient_config.h.in
rebuilding Makefile.in files


# libtoolize
libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.in and
libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.

# sh ./buildconf.sh
rebuilding Makefile.in files

四、編譯及安裝

同樣在 libsphinxclient 的目錄下
1. 組態

# ./configure
checking MySQL include files... configure: error: missing include files.

******************************************************************************

ERROR: cannot find MySQL include files.
Check that you do have MySQL include files installed.
The package name is typically 'mysql-devel'.

出錯,出現cannot find MySQL include files.錯誤,原因是我系統升級php5.5時重裝sphinx就出錯了。後來參考[6]的解答解決了:

# yum install mysql-devel

重新組態
# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
...中略..
checking for strings.h... (cached) yes
checking for unistd.h... (cached) yes
checking for stdint.h... (cached) yes
checking for gethostbyname in -lnsl... yes
checking for connect in -lsocket... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating sphinxclient_config.h
config.status: executing depfiles commands
config.status: executing libtool commands


2.安裝
# make install
..前略..
running: make INSTALL_ROOT="/var/tmp/pear-build-roottfoIy2/install-sphinx-1.3.3" install
Installing shared extensions:     /var/tmp/pear-build-roottfoIy2/install-sphinx-1.3.3/usr/lib64/php/modules/
running: find "/var/tmp/pear-build-roottfoIy2/install-sphinx-1.3.3" | xargs ls -dils
1054610   4 drwxr-xr-x. 3 root root   4096 2015-05-26 14:40 /var/tmp/pear-build-roottfoIy2/install-sphinx-1.3.3
1054633   4 drwxr-xr-x. 3 root root   4096 2015-05-26 14:40 /var/tmp/pear-build-roottfoIy2/install-sphinx-1.3.3/usr
1054634   4 drwxr-xr-x. 3 root root   4096 2015-05-26 14:40 /var/tmp/pear-build-roottfoIy2/install-sphinx-1.3.3/usr/lib64
1054635   4 drwxr-xr-x. 3 root root   4096 2015-05-26 14:40 /var/tmp/pear-build-roottfoIy2/install-sphinx-1.3.3/usr/lib64/php
1054636   4 drwxr-xr-x. 2 root root   4096 2015-05-26 14:40 /var/tmp/pear-build-roottfoIy2/install-sphinx-1.3.3/usr/lib64/php/modules
1054632 156 -rwxr-xr-x. 1 root root 156005 2015-05-26 14:40 /var/tmp/pear-build-roottfoIy2/install-sphinx-1.3.3/usr/lib64/php/modules/sphinx.so

Build process completed successfully Installing '/usr/lib64/php/modules/sphinx.so'
install ok: channel://pecl.php.net/sphinx-1.3.3
configuration option "php_ini" is not set to php.ini location
You should add "extension=sphinx.so" to php.ini


3. PHP新增extension
# cd /etc/php.d
新增一個檔案叫 sphinx.ini 裡面只有一行:
extension=sphinx.so

存檔後重啟 APACHE。

4. 檢查
# php -m | grep sphinx
sphinx

如果一片空白代表沒成功,或者你可以用 phpinfo(); 來看

成功了,就可以使用所有的sphinx函數,有空再來寫使用說明。

五、新版安裝及解除

解除安裝
# rpm -e sphinx

PHP>5.5以後的版本不必再這麼裝了,有一個原生套件能使用

# yum install php-sphinx

之前的苦工...算是白忙了一場

參考資料

[1] http://sphinxsearch.com/forum/view.html?id=7580
[2] http://sphinxsearch.com/downloads/
[3] http://ask.xmodulo.com/failed-to-run-libtoolize-no-such-file-or-directory-error.html
[4] http://itlab.idcquan.com/linux/server/937609.html
[5] http://stackoverflow.com/questions/18978252/error-libtool-library-used-but-libtool-is-undefined
[6] http://stackoverflow.com/questions/14749148/where-to-find-mysql-include-files-for-configuring-sphinx-on-mamp


原文編修 2015-05-26 15:30:50

你可能感興趣的文章

[Linux] mongodb 初步--1/3 我使用mongo 的一些大小事:安裝及基本操作

[Centos7] SSL自簽憑證+APACHE+Selinux SSL的自簽憑證

[Centos7] 安裝phpMyAdmin Centos 7有新的方式可以安裝phpmyadmin,不必再採用過去的tarball安裝法。

[Centos] 安裝及使用postfix,設定虛擬帳號及轉寄 使用postfix來設定虛擬帳號及轉寄

[Centos6] php5.3升級為php5.6 Centos6 + php5.6 升級

安裝SPHINX支援中文 新版本的 sphinx 和舊版不同,網路上很多範例和教學是不能用的。此文是安裝和設定方法分享

[CentOS] 改錯fstab 無法開機怎麼辦? Linux 改錯fstab 無法開機怎麼辦?

PHP for sphinx 函式庫安裝 PECL/sphinx PHP>= 5.2.2 已經能原生支援 sphinx,可是預設的沒有裝,我們得自己裝才能用

TFTP Server 安裝及使用 讓設備的網路設定檔或是韌體經由TFTP拷備出來,操作的方法

[Centos7] 安裝php套件管理程式Composer+ Codeignioter3 很多人在用的套件管理程式 Composer+ Codeignioter3+ 指定安裝目錄

我有話要說


限制:留言最高字數1000字,超過部分會被截掉。請注意:留言不可帶有網址,會被濾掉。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

[MAC] 截取螢幕畫面的方法 截取螢幕畫面的方法,在MAC中叫作螢幕快照,英文是screenshot

Linux shell 的date表示法 linux下SHELL中的date表示法

精讚的版面變化 ▓此文僅作為舊文的記錄▓ 這篇文章為了紀念改版完成而撰寫。 原本的部落格是民國97年的作品,那時還是用舊有的技術來寫,很

[AS3] 物件加上超連結的方法 物件加上超連結,可讓使用者點擊的方法

在Centos7 下安裝 Wildfly10 wildfly以前叫JBoss,2014.11.20改名叫Wildfly,起始版本是Wildfly8,現在已經出到Wil