php扩展AMQP,安装报错解决

接下来来安装php扩展AMQP,安装了它以后,才能用PHP操作rabbitmq。

wget https://pecl.php.net/get/amqp-1.4.0.tgz
tar -zxvf amqp-1.4.0.tgz
cd amqp-1.4.0
/lnmp/php/bin/phpize
./configure --with-php-config=/lnmp/php/bin/php-config

安装到这,就报了错:
checking for amqp files in default path… not found
configure: error: Please reinstall the librabbit-mq distribution

在网上搜了搜,找到了解决方法(http://www.cnphp6.com/archives/68356):
需要安装rabbitmq-c,rabbitmq-c是一个用于C语言的,与AMQP server进行交互的client库。
下载地址:https://github.com/alanxz/rabbitmq-c

unzip rabbitmq-c-master.zip
cd rabbitmq-c-master
autoreconf -i
./configure --prefix=/lnmp/rabbitmq-c
make
make install

额,接着安装PHP扩展AMQP

./configure --with-php-config=/lnmp/php/bin/php-config --with-amqp --with-librabbitmq-dir=/lnmp/rabbitmq-c
make && make install

草,又报错啦:
/software/amqp-1.4.0/amqp_exchange.c:515: error: incompatible type for argument 7 of ‘amqp_exchange_declare’
/lnmp/rabbitmq-c//include/amqp_framing.h:798: note: expected ‘amqp_boolean_t’ but argument is of type ‘amqp_table_t’
/software/amqp-1.4.0/amqp_exchange.c:515: error: too few arguments to function ‘amqp_exchange_declare’
make: *** [amqp_exchange.lo] Error 1
在https://github.com/pdezwart/php-amqp/issues/127找到了方法:
应该是安装的rabbitmq-c的版本太高了(安装的是 v0.6.0),下载了v0.5.2版本(https://github.com/alanxz/rabbitmq-c/releases/download/v0.5.2/rabbitmq-c-0.5.2.tar.gz),重新安装rabbitmq-c,重新安装php扩展AMQP,终于可以啦。真是一波三折啊。

在php配置文件里将扩展加上,重启一下,看phpinfo,显示如下图即安装成功。

原文地址:https://www.cnblogs.com/zhming26/p/6141028.html