Home  >  Article  >  Backend Development  >  Detailed explanation of how to install php-kafka and php-rdkafka extensions in PHP under Linux

Detailed explanation of how to install php-kafka and php-rdkafka extensions in PHP under Linux

藏色散人
藏色散人forward
2020-02-01 19:10:402874browse

Detailed explanation of how to install php-kafka and php-rdkafka extensions in PHP under Linux

Specific steps:

1. Install librdkafka

cd /usr/local/src  #进入安装包存放目录
wget https://github.com/edenhill/librdkafka/archive/master.zip  #下载
mv master.zip librdkafka-master.zip  #修改包名
unzip librdkafka-master.zip  #解压
cd librdkafka-master  #进入安装文件夹
./configure   #配置
make  #编译
make install  #安装

2. Install phpkafka

cd /usr/local/src  #进入安装包存放目录
wget https://github.com/EVODelavega/phpkafka/archive/master.zip  #下载
mv master.zip phpkafka-master.zip  #修改包名
unzip phpkafka-master.zip   #解压
cd phpkafka-master   #进入安装文件夹
/usr/local/php/bin/phpize  #加载php扩展模块
./configure --enable-kafka --with-php-config=/usr/local/php/bin/php-config   #配置
make  #编译
make install  #安装

3. Modify the php configuration file

vi /usr/local/php/etc/php.ini  #打开php配置文件,在最后一行添加下面的代码
extension="kafka.so"
:wq!  #保存退出

4. Test

The following code is saved as phpinfo.php

<?php
phpinfo();
?>

Upload to the website directory and search for kafka, as shown in the figure below, indicating that the installation is successful!

2. During the process, I encountered several pitfalls. After completing the previous steps, I found that the extension was not loaded normally. It was strange that when I looked at the error log of PHP, I could not find the file librdkafka.so.1. The installation of librdkafka is normal. Baidu found a solution

When php loads librdkafka, it will find the corresponding file under /usr/lib/ and report an error if it is not found, so adding a soft link is the simplest Method

ln -s /usr/local/lib/librdkafka.so.1 /usr/lib/

After adding the soft link, remember to update the soft link for it to take effect

ldconfig

Then restart php-fpm and everything will be ok. ~~.

For more php related knowledge, please visit php tutorial!

The above is the detailed content of Detailed explanation of how to install php-kafka and php-rdkafka extensions in PHP under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete