CentOS下安裝PHP的AMQP擴展方法和步驟


AMQP,即Advanced Message Queuing Protocol,一個提供統一消息服務的應用層標准高級消息隊列協議,是應用層協議的一個開放標准,為面向消息的中間件設計。基於此協議的客戶端與消息中間件可傳遞消息,並不受客戶端/中間件不同產品,不同的開發語言等條件的限制。Erlang中的實現有 RabbitMQ等。

主要是兩個包
    1.rabbitmq-c的包
    2.amqp的包

1、下載
    首先是rabbitmq-c-0.5.2.tar.gz包,可以訪問https://github.com/alanxz/rabbitmq-c去下載

wget https://github.com/alanxz/rabbitmq-c/releases/download/v0.5.2/rabbitmq-c-0.5.2.tar.gz

     附上我下載好的rabbitmq-c-0.5.2.tar.gz  點擊下載

  然后下載amqp-1.9.1.tgz,也可以去下載最新的http://pecl.php.net/package/amqp

wget http://pecl.php.net/get/amqp-1.9.1.tgz


2、安裝
    1.先把兩個包全都解壓

tar zxvf rabbitmq-c-0.5.2.tar.gz
tar zxvf amqp-1.9.1.tgz

    兩個是有先后順序的
    
    2.安裝rabbitmq-c-0.5.2

cd rabbitmq-c-0.5.2
./configure --prefix=/usr/local/rabbitmq-c-0.5.2

   之后會有輸出如下:

rabbitmq-c build options:
Host: x86_64-unknown-linux-gnu
Version: 0.5.2
SSL/TLS: openssl
Tools: yes
Documentation: no
Examples: yes

安裝

make && make install    

    如果不知道安裝成功與否,可以每一步都用echo $?檢查,顯示0為正常
    
    3.安裝amqp-1.9.1

  phpize命令在安裝AMQP插件是報錯phpize:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF envir的解決方法

cd /usr/src && wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
tar -zvxf m4-1.4.9.tar.gz # cd m4-1.4.9/
./configure && make && make install # cd ../
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
tar -zvxf autoconf-2.62.tar.gz
cd autoconf-2.62/
./configure && make && make install

或者:
yum install -y m4 autoconf
cd amqp-1.9.1
phpize

執行完phpize命令后你應該看到類似下邊的內容

Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525    

    一般安裝完PHP都會有這個命令,要是沒有這個命令的話需要安裝一下:yum install php-devel
    用find / -name phpize查找命令路徑

./configure --with-php-config=/usr/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c-0.5.2/

    PS:--with-php-config=/usr/bin/php-config  這個php-config根據你裝的php而定,要是找不到請用find / -name php-config查找
    --with-librabbitmq-dir=/usr/local/rabbitmq-c-0.5.2/  這個是指定你安裝的rabbitmq-c的目錄,我安裝的是/usr/local/rabbitmq-c-0.5.2/因為在安裝rabbitmq-c的時候我自己指定了安裝目錄了.

make && make install

   
    安裝完成最后一行會輸出:
        Installing shared extensions:     /usr/lib64/php/modules/
        以上是正常情況下,要是你自己編譯的php,那么他會提示你別的路徑,此時你需要找到這個路徑里邊的amqp.so文件,將他拷貝到/usr/lib64/php/modules/下.
        
    4.編輯php.ini文件添加一下內容

[rabbitmq]
extension=amqp.so
extension_dir = "/usr/lib64/php/modules/"

    重啟php-fpm即可。
        
3、測試安裝是否成功
    
    php測試腳本
    php測試rabbitmq的php擴展插件腳本

<?php
$cnn = new AMQPConnection();
$cnn->setHost('127.0.0.1');
$cnn->setLogin('guest');
$cnn->setPassword('guest');
if($cnn->connect()){
        echo '連接成功';
}
?>

 

configure: error: Cannot find php-config. Please use --with-php-config=PATH 錯誤的解決方案

find / type f -name "php-config"
/usr/local/php/bin/php-config #使用這個路徑

安裝完PHP沒有php.ini文件

find / -type f -name "php.ini-production"
/tools/php-7.1.9/php.ini-production
cp /tools/php-7.1.9/php.ini-production /etc/php.ini

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM