[精讚] [會員登入]
1382

PHP for sphinx 函式庫安裝

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

分享此文連結 //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

END

你可能感興趣的文章

EXCEL+phpPgAdmin 使用phpPgAdmin 匯出資料 直接使用phpPgAmin下載資料的方法

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

[Docker] IPv6+nginx+php 讓docker中的容器支援ipv6,讀取到外部ipv6 docker中的容器要如何讀取到來源的ip6?這裡眉角很多。

[CentOS6] 設定 sendmail Centos6上設定sendmail,基本上sendmail會設定多半是為了寄系統信和收垃圾信(喂!!?)

[Rocky9] Rocky Linux 9網路重啟 network restart? Rocky Linux 9網路重啟 network restart 指令不見了,該怎麼辦?

使用RRDTOOL來繪製流量圖 使用RRDTOOL來製作流量圖的簡略說明

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

[Freebsd] 定時測試 ADSL 是否斷線並重連 中華電信 ADSL 雖有固定 ip,可是他卻會不定時「斷線」, 使用以下的 方法可以定時測試是否斷線,以及重新撥接。

[Freebsd] 使用 ADSL 撥接上網 Freebsd上要使用 ADSL 撥接上網,該如何設定?

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

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

[CodeIgniter3] 解決無法上傳特定檔案(.sb2)的問題 上傳時出現The filetype you are attempting to upload is not allowed,要怎麼解決?