標籤:oar .com color port target with 內容 this rabbit
用於ubuntu的預設源裡面沒有php5-amqp這個包,所以要用上amqp得考手動編譯。
參考手冊 http://php.net/manual/pl/book.amqp.php
首先安裝必須的php編譯工具
[html] view plain copy
- sudo apt-get install php5-dev
安裝rabbitmq的庫
[html] view plain copy
- sudo apt-get install librabbitmq-dev
如果你的Linux發行版沒有現成的librabbitmq-dev包,那麼可以通過下載源碼編譯安裝
然後如果你沒有安裝git話請安裝一下git,因為我們要從官方的版本庫中擷取原始碼
# 複製源碼並編譯
[html] view plain copy
- git clone git://github.com/alanxz/rabbitmq-c.git
- cd rabbitmq-c
- git submodule init
- git submodule update
# 編譯庫
[html] view plain copy
- autoreconf -i && ./configure && make && sudo make install
然後我們需要去下載php擴充的原始碼,地址在此:http://pecl.php.net/package/amqp
當前最新版本為1.0.10
[html] view plain copy
- wget http://pecl.php.net/get/amqp-1.0.10.tgz
- tar zxf amqp-1.0.10.tgz
- cd amqp-1.0.10/
- phpize && ./configure --with-amqp && make && sudo make install
如果報錯
[html] view plain copy
- /root/amqp-1.0.9/amqp_queue.c: In function ‘read_message_from_channel’:
- /root/amqp-1.0.9/amqp_queue.c:341:11: error: ‘AMQP_FIELD_KIND_U64’ undeclared (first use in this function)
- /root/amqp-1.0.9/amqp_queue.c:341:11: note: each undeclared identifier is reported only once for each function it appears in
- /root/amqp-1.0.9/amqp_queue.c: In function ‘zim_amqp_queue_class_nack’:
- /root/amqp-1.0.9/amqp_queue.c:1093:2: error: unknown type name ‘amqp_basic_nack_t’
- /root/amqp-1.0.9/amqp_queue.c:1113:3: error: request for member ‘delivery_tag’ in something not a structure or union
- /root/amqp-1.0.9/amqp_queue.c:1114:3: error: request for member ‘multiple’ in something not a structure or union
- /root/amqp-1.0.9/amqp_queue.c:1115:3: error: request for member ‘requeue’ in something not a structure or union
- /root/amqp-1.0.9/amqp_queue.c:1120:3: error: ‘AMQP_BASIC_NACK_METHOD’ undeclared (first use in this function)
- make: *** [amqp_queue.lo] Error 1
是因為預設的librabbitmq-dev發行版的包比較舊,用上面git方式編譯安裝最新即可。
去下載最新的php擴充的原始碼,地址在此:http://pecl.php.net/package/amqp
- wget http://pecl.php.net/get/amqp-x.x.x.tgz
- tar zxf amqp-x.x.x.tgz
- cd amqp-x.x.x/
- 繼續執行
- phpize && ./configure --with-amqp && make && sudo make install
最後一步建立設定檔
[html] view plain copy
- sudo echo "extension = amqp.so" > /etc/php5/conf.d/amqp.ini
重啟web伺服器在phpinfo頁面中看到以下內容說明安裝好了
sudo /etc/init.d/apache2 restart
http://localhost/phpinfo.php
ubuntu下手動安裝php-amqp模組教程