[精讚] [會員登入]
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

你可能感興趣的文章

[Centos8][Rocky9] ffmpeg 安裝及使用,用ffmpef製作gif動畫 用ffmpef製作gif動畫,但是他的功能很強大,可以用指令來執行

[Centos8] 網頁化的系統管理介面 cockpit Centos8 提供一個網頁化的管理介面,稱為駕駛艙,值得一試

[CENTOS7] 使用 logrotate 來整理wildfly日誌檔 解決 wildfly 的日誌檔不斷長大的問題

使用GPG檔案加解密 簡易的檔案加解密方式,可以讓你重要的資料包括文字檔加解密。

[APACHE] PHP<5.5及 PHP>=5.5 安裝APC php5.5版後的apc只能手動安裝,此文包含php<5.5及php>=5.5兩種安裝方法

[Centos7] 新的防火牆firewalld Centos7新的防火牆firewalld 和前面的iptables有很大的不同

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

魔球中小女孩唱的歌 The show 魔球中小女孩唱的歌 The show

[PHP] 檢查檔案是否是圖檔 使用getimagesize函數檢查檔案是否是圖檔

「許功蓋」的字以及源由 有玩過電腦一段時間的人,都聽過這個人(有一天我才發現7年級的竟然都不認識這個

[PHP]解決ksort新增的SORT_NATURAL|SORT_FLAG_CASE方法 php>=5.4中ksort函數多了SORT_NATURAL 和 SORT_FLAG_CASE 旗標,對舊版的PHP中要怎麼辦?

Sound of Music @比利時中央車站 比利時中央車站的快閃表演:「真善美」