php7安装amqp扩展的方法(基于Centos6.x)

当前使用Centos6.x系统,php使用7.1版本,wlnmp一键包已支持该扩展

php7安装amqp扩展(基于Centos7.x)参考:topic/php7/437499.html

amqp扩展包地址:

https://pecl.php.net/package/amqp

与Centos7不同的是,在Centos6.x环境下需要手动编译rabbitmq-c,否则会看到如下报错

amqp-1.9.4/amqp.c: In function ‘zm_startup_amqp’:
amqp-1.9.4/amqp.c:177: error: ‘AMQP_SASL_METHOD_EXTERNAL’ undeclared (first use in this function)
amqp-1.9.4/amqp.c:177: error: (Each undeclared identifier is reported only once
amqp-1.9.4/amqp.c:177: error: for each function it appears in.)
make: *** [amqp.lo] Error 1

1、安装所需依赖,如果在编译时还提示缺少其他依赖,请自行安装

yum install autoconf gcc gcc-c++ cmake librabbitmq-devel librabbitmq

2、编译rabbitmq-c

注意:rabbitmq-c-0.9.0与rabbitmq-c-0.8.0版本编译方式不同,我这里以最新的0.9.0为例

wget https://github.com/alanxz/rabbitmq-c/archive/v0.9.0.tar.gz
tar xf v0.9.0.tar.gz
cd rabbitmq-c-0.9.0/
mkdir build && cd build
cmake ..
make
make install
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib64/pkgconfig/librabbitmq.pc
-- Installing: /usr/local/lib64/librabbitmq.so.4.3.0
-- Installing: /usr/local/lib64/librabbitmq.so.4
-- Installing: /usr/local/lib64/librabbitmq.so
-- Installing: /usr/local/lib64/librabbitmq.a
-- Installing: /usr/local/include/amqp.h
-- Installing: /usr/local/include/amqp_framing.h
-- Installing: /usr/local/include/amqp_tcp_socket.h
-- Installing: /usr/local/include/amqp_ssl_socket.h

3、下载amqp最新稳定版

wget https://pecl.php.net/get/amqp-1.9.4.tgz
tar xf amqp-1.9.4.tgz
cd amqp-1.9.4
/usr/local/php/bin/phpize

根据自己phpize的位置来运行即可(不知道phpize在哪的直接find / -name phpize查找),运行完提示下面信息,然后编译

Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303

4、编译扩展模块

./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

执行完成后会显示扩展模块编译到的目录/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/

5、修改php.ini添加扩展

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/"
extension=amqp.so

注意:如果之前配置过extension_dir路径了,则只需要配置extension=amqp.so即可

保存退出,重启php

通过phpinfo可看到,扩展已生效

64b44701f7a5a75c56923740e7f811f.png

更多相关PHP7内容请访问:《PHP7》教程

以上就是php7安装amqp扩展的方法(基于Centos6.x)的详细内容,更多请关注其它相关文章!