PHP for sphinx 函式庫安裝

URL Link //n.sfs.tw/10059

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