Home > Backend Development > PHP Tutorial > 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

藏色散人
Release: 2023-04-08 12:10:01
forward
2971 people have browsed it

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  #安装
Copy after login

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  #安装
Copy after login

3. Modify the php configuration file

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

4. Test

The following code is saved as phpinfo.php

<?php
phpinfo();
?>
Copy after login

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/
Copy after login

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!

Related labels:
php
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template