給PHP安裝amqp擴充套件
有史以來最坑爹的一次擴充套件安裝,不曉得諸位有沒有嘗試過…………各種報錯啊!有木有?!¥#@%%&*……
搗鼓半天,只編譯了個0.1.x的擴充套件版本,瞅了下,擦,函式少的可憐啊- -|||
不行,繼續~
經過一天的努力,老天總算開眼了,趕緊總結下吧~
----------------------------------------------- 我是分割線 ---------------------------------------------------
AMQP——高階訊息佇列協議,目前比較有名氣的實現大概就是大名鼎鼎的RabbitMQ了。
To install the AMQP PHP extension, you must first install the » librabbitmq library. You will need the 0-9-1 version of the rabbitmq-c client library, linked to the rabbitmq-codegen version that corresponds to the version of the broker you are using. Use the following steps to download and install the library:
# Download the rabbitmq-c library @ version 0-9-1
hg clone http://hg.rabbitmq.com/rabbitmq-c/rev/b01825ecc112 rabbitmq-c
cd rabbitmq-c
# Add the codegen requirement. To find the full list, go here: http://hg.rabbitmq.com/rabbitmq-codegen/tags
# and copy the URL for the appropriate broker version.
hg clone http://hg.rabbitmq.com/rabbitmq-codegen/rev/16bbcb711380 codegen
# Configure, compile and install
autoreconf -i && ./configure && make && sudo make install
擴充套件是C寫的,由於C與RabbitMQ通訊一般需要依賴rabbitmq-c庫(也就是librabbitmq),所以編譯擴充套件前需要先裝依賴庫。好吧,那就按要求裝吧~
原文是用hg工具,需要裝mercurial
wget https://github.com/alanxz/rabbitmq-c/tarball/0.2
tar zxvf 0.2
cd alanxz-rabbitmq*
(為什麼0.2版?好吧,我也不知道,總之它的各版本相容性非常不好,經過我屢試屢敗屢敗試……發現0.2版還算順利 - -)
wget https://github.com/rabbitmq/rabbitmq-codegen/tarball/master
tar zxvf master
mv rabbitmq-* codegen
(上面這步必須要把其解壓,並放到rabbitmq-c的目錄中的codegen目錄中,也就是上面最後那步做的。)
按照手冊介紹,先進行:
autoreconf -i
如果你一切順利,沒有報錯,那麼恭喜了!後面則是常規操作:
./configure && make && make install
如果仍未報錯,哇塞,我只能說你NB!可以直接進行擴充套件編譯了。
不過大部分情況下你或許和我一樣遇到各種各樣報錯資訊,那麼後面我們再說,這裡先把編譯擴充套件順帶說完。
直接回到官方下載(我下載的是1.0.0版,新的版本我沒事試,應該也可以的) http://pecl.php.net/package/amqp ,並編譯成so檔案 OR shell:
wget http://pecl.php.net/get/amqp-1.0.0.tgz
tar zxvf amqp-1.0.0.tgz
cd amqp-1.0.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp
make && make install
(/usr/local/php/bin/phpize 和 /usr/local/php/bin/php-config 為實際php所在目錄,如果不清楚,可以whereis php檢視。)
如果之前的步驟順利,這步應該沒什麼問題,直接在php.ini中新增生成的amqp.so,重啟httpd或php-cgi即可,不再贅述。
---------------------------------------------------我是分割線----------------------------------------------------
好了,如果你和我一樣悲催,從autoreconf -i就開始作死地報錯,那麼我這裡提供一些可能有用的處理方法。
autoreconf 時有可能遇到如下報錯:
onfigure.ac:60: error: possibly undefined macro: AS_CASE
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.ac:69: error: possibly undefined macro: AS_IF
configure.ac:92: error: possibly undefined macro: AC_PATH_PROGS_FEATURE_CHECK
configure.ac:97: error: possibly undefined macro: AC_MSG_RESULT
configure:2907: error: possibly undefined macro: m4_foreach_w
autoreconf: /usr/bin/autoconf failed with exit status: 1
奇怪的是,當我再次執行卻報不同的錯。。。
configure.ac: installing `./install-sh'
configure.ac: installing `./missing'
configure.ac:34: installing `./config.guess'
configure.ac:34: installing `./config.sub'
Makefile.am:3: Libtool library used but `LIBTOOL' is undefined
Makefile.am:3:
Makefile.am:3: The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
Makefile.am:3: to `configure.ac' and run `aclocal' and `autoconf' again.
Makefile.am: C objects in subdir but `AM_PROG_CC_C_O' not in `configure.ac'
Makefile.am: installing `./compile'
Makefile.am: installing `./depcomp'
autoreconf: automake failed with exit status: 1
首先確保一些必要的依賴庫是否已安裝,如:libtool、autoconf、automake 等
這個大家自行google下載並編譯安裝,常規操作,沒啥說的,這裡我直接yum了:
yum install libtool autoconf automake
看下libtoolize在哪:
whereis libtoolize
顯示例如:libtoolize: /usr/bin/libtoolize,則可執行一下
/usr/bin/libtoolize
還有可能會出現這種錯:
/usr/share/aclocal/libmcrypt.m4:17: warning: underquoted definition of AM_PATH_LIBMCRYPT
/usr/share/aclocal/libmcrypt.m4:17: run info '(automake)Extending aclocal'
/usr/share/aclocal/libmcrypt.m4:17: or see http://sources.redhat.com/automake/automake.html#Extending-aclocal
解決辦法如下:
編輯:/usr/share/aclocal/libmcrypt.m4
修改17行的:AC_DEFUN(AM_PATH_LIBMCRYPT, 為 AC_DEFUN([AM_PATH_LIBMCRYPT],
---------------------------------------------------我是分割線----------------------------------------------------
/usr/bin/libtoolize 時可能會報的錯:
libtoolize: putting auxiliary files in `.'.
libtoolize: linking file `./ltmain.sh'
libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and
libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
報錯很明確,按照提示操作即可:
編輯:configure.ac
新增一行:AC_CONFIG_MACRO_DIR([m4])
重新執行:/usr/bin/libtoolize
編輯:Makefile.am
新增一行:ACLOCAL_AMFLAGS=-I m4
---------------------------------------------------我是分割線----------------------------------------------------
./configure 時可能會報的錯:
checking location of AMQP codegen directory... configure: error: could not find AMQP spec file at "'/codegen/amqp-0.9.1.json'"
configure檔案中目錄與實際情況不符,雖然可以通過手動修改解決,但不建議,其實應該是rabbitmq-c和codegen的版本不匹配造成的,更換版本。
checking finding a python with simplejson installed... configure: error: could not find a python that can 'import simplejson'
很明顯,該錯誤是由於python缺少simplejson包造成,可通過easy_install方式安裝即可。
---------------------------------------------------我是分割線----------------------------------------------------
還有更多報錯情況,沒有一一記錄,總之解決方法就是:“報錯資訊”+“google”!
BTW:相信搜一會兒你就會由衷得體會到:F*CK THE GFW!!!