ubuntu下手动安装php-amqp模块教程

Posted 爱漂泊人生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu下手动安装php-amqp模块教程相关的知识,希望对你有一定的参考价值。

用于ubuntu的默认源里面没有php5-amqp这个包,所以要用上amqp得考手动编译。

参考手册 http://php.net/manual/pl/book.amqp.php

首先安装必须的php编译工具

[html] view plain copy
  1. sudo apt-get install php5-dev  


安装rabbitmq的库

[html] view plain copy
  1. sudo apt-get install librabbitmq-dev  


如果你的Linux发行版没有现成的librabbitmq-dev包,那么可以通过下载源码编译安装
然后如果你没有安装git话请安装一下git,因为我们要从官方的版本库中获取源代码
# 克隆源码并编译

[html] view plain copy
  1. git clone git://github.com/alanxz/rabbitmq-c.git  
  2. cd rabbitmq-c  
  3. git submodule init  
  4. git submodule update  


# 编译库

[html] view plain copy
  1. autoreconf -i && ./configure && make && sudo make install  


然后我们需要去下载php扩展的源代码,地址在此:http://pecl.php.net/package/amqp

当前最新版本为1.0.10

[html] view plain copy
  1. wget http://pecl.php.net/get/amqp-1.0.10.tgz  
  2. tar zxf amqp-1.0.10.tgz  
  3. cd amqp-1.0.10/  
  4. phpize && ./configure --with-amqp && make && sudo make install  

如果报错

[html] view plain copy
  1. /root/amqp-1.0.9/amqp_queue.c: In function ‘read_message_from_channel’:  
  2. /root/amqp-1.0.9/amqp_queue.c:341:11: error: ‘AMQP_FIELD_KIND_U64’ undeclared (first use in this function)  
  3. /root/amqp-1.0.9/amqp_queue.c:341:11: note: each undeclared identifier is reported only once for each function it appears in  
  4. /root/amqp-1.0.9/amqp_queue.c: In function ‘zim_amqp_queue_class_nack’:  
  5. /root/amqp-1.0.9/amqp_queue.c:1093:2: error: unknown type name ‘amqp_basic_nack_t’  
  6. /root/amqp-1.0.9/amqp_queue.c:1113:3: error: request for member ‘delivery_tag’ in something not a structure or union  
  7. /root/amqp-1.0.9/amqp_queue.c:1114:3: error: request for member ‘multiple’ in something not a structure or union  
  8. /root/amqp-1.0.9/amqp_queue.c:1115:3: error: request for member ‘requeue’ in something not a structure or union  
  9. /root/amqp-1.0.9/amqp_queue.c:1120:3: error: ‘AMQP_BASIC_NACK_METHOD’ undeclared (first use in this function)  
  10. make: *** [amqp_queue.lo] Error 1  


是因为默认的librabbitmq-dev发行版的包比较旧,用上面git方式编译安装最新即可。

去下载最新的php扩展的源代码,地址在此:http://pecl.php.net/package/amqp

  1. wget http://pecl.php.net/get/amqp-x.x.x.tgz  
  2. tar zxf amqp-x.x.x.tgz  
  3. cd amqp-x.x.x/  
  4. 继续执行
  5. phpize && ./configure --with-amqp && make && sudo make install

最后一步创建配置文件

[html] view plain copy
  1. 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模块教程的主要内容,如果未能解决你的问题,请参考以下文章

Linux ubuntu手动安装gitlabdocker安装gitlab教程及配置

stable-diffusion-webui的安装教程 ubuntu

ubuntu下手动安装MongoDB

Ubuntu下手动安装vscode

怎样手动安装python的包

Ubuntu下手动安装NextCloud