安装RabbitMq的PHP扩展
Centos7
- 安装rabbitmq客户端
[root@guangzhou src]# wget https://github.com/alanxz/rabbitmq-c/archive/v0.9.0.tar.gz
[root@guangzhou src]# mv v0.9.0.tar.gz rabbitmq-c-v0.9.0.tar.gz
[root@guangzhou src]# tar -zxvf rabbitmq-c-v0.9.0.tar.gz
[root@guangzhou src]# cd rabbitmq-c-0.9.0/
[root@guangzhou rabbitmq-c-0.9.0]# mkdir build && cd build
#当cmake根据rabbitmq-c的根目录下的CMakeList.txt创建Makefile文件时,会将Makefile文件放进build目录
[root@guangzhou build]# cmake ..
[root@guangzhou build]# cd ..
[root@guangzhou rabbitmq-c-0.9.0]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c-0.9.0
[root@guangzhou rabbitmq-c-0.9.0]# cmake --build . --target install
可能会报错
/root/rabbitmq-c-0.9.0/tools/publish.c: In function ‘main’:
/root/rabbitmq-c-0.9.0/tools/publish.c:87:23: error: ‘POPT_ARG_ARGV’ undeclared (first use in this function)
{"header", 'H', POPT_ARG_ARGV, &headers, 0,
^
/root/rabbitmq-c-0.9.0/tools/publish.c:87:23: note: each undeclared identifier is reported only once for each function it appears in
gmake[2]: *** [tools/CMakeFiles/amqp-publish.dir/publish.c.o] Error 1
gmake[1]: *** [tools/CMakeFiles/amqp-publish.dir/all] Error 2
gmake: *** [all] Error 2
遇到这种情况需要下载Popt 重新安装 网址是:http://www.linuxfromscratch.org/blfs/view/svn/general/popt.html
./configure --prefix=/usr --disable-static && make && make install
- 安装rabbitmq的php扩展
[root@guangzhou src]# wget http://pecl.php.net/get/amqp-1.9.4.tgz
[root@guangzhou src]# tar -zxvf amqp-1.9.4.tgz
[root@guangzhou src]# cd amqp-1.9.4/
[root@guangzhou amqp-1.9.4]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
[root@guangzhou amqp-1.9.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c-0.9.0
[root@guangzhou amqp-1.9.4]# make
/bin/sh /usr/local/src/amqp-1.9.4/libtool --mode=link cc -DPHP_ATOM_INC -I/usr/local/src/amqp-1.9.4/include -I/usr/local/src/amqp-1.9.4/main -I/usr/local/src/amqp-1.9.4 -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/usr/local/rabbitmq-c-0.9.0/include -DHAVE_CONFIG_H -g -O2 -o amqp.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/src/amqp-1.9.4/modules amqp.lo amqp_type.lo amqp_exchange.lo amqp_queue.lo amqp_connection.lo amqp_connection_resource.lo amqp_channel.lo amqp_envelope.lo amqp_basic_properties.lo amqp_methods_handling.lo amqp_timestamp.lo amqp_decimal.lo -Wl,-rpath,/usr/local/rabbitmq-c-0.9.0/lib -L/usr/local/rabbitmq-c-0.9.0/lib -lrabbitmq
cc -shared .libs/amqp.o .libs/amqp_type.o .libs/amqp_exchange.o .libs/amqp_queue.o .libs/amqp_connection.o .libs/amqp_connection_resource.o .libs/amqp_channel.o .libs/amqp_envelope.o .libs/amqp_basic_properties.o .libs/amqp_methods_handling.o .libs/amqp_timestamp.o .libs/amqp_decimal.o -L/usr/local/rabbitmq-c-0.9.0/lib -lrabbitmq -Wl,-rpath -Wl,/usr/local/rabbitmq-c-0.9.0/lib -Wl,-soname -Wl,amqp.so -o .libs/amqp.so
/usr/bin/ld: cannot find -lrabbitmq
collect2: error: ld returned 1 exit status
make: *** [amqp.la] 错误 1
#这里使用make命令时会报错,对rabbitmq-c-0.9.0目录创建软链指向
[root@guangzhou amqp-1.9.4]# ln -s /usr/local/rabbitmq-c-0.9.0/lib64 /usr/local/rabbitmq-c-0.9.0/lib
#再次执行make命令
[root@guangzhou amqp-1.9.4]# make
[root@guangzhou amqp-1.9.4]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/
#更改php.ini,加上extension=amqp.so
root@guangzhou etc]# vim php.ini
[root@guangzhou etc]# php --ri amqp
amqp
Version => 1.9.4
Revision => release
Compiled => Jan 30 2020 @ 17:31:44
AMQP protocol version => 0-9-1
librabbitmq version => 0.9.0
Default max channels per connection => 256
Default max frame size => 131072
Default heartbeats interval => 0
Directive => Local Value => Master Value
amqp.auto_ack => 0 => 0
amqp.cacert => no value => no value
amqp.cert => no value => no value
amqp.channel_max => 256 => 256
amqp.connect_timeout => 0 => 0
amqp.frame_max => 131072 => 131072
amqp.heartbeat => 0 => 0
amqp.host => localhost => localhost
amqp.key => no value => no value
amqp.login => guest => guest
amqp.password => guest => guest
amqp.port => 5672 => 5672
amqp.prefetch_count => 3 => 3
amqp.read_timeout => 0 => 0
amqp.sasl_method => 0 => 0
amqp.timeout => no value => no value
amqp.verify => 1 => 1
amqp.vhost => / => /
amqp.write_timeout => 0 => 0
[root@guangzhou etc]# systemctl restart php-fpm.service