How do I install an extension of Kafka for PHP?
Solution 1
Quick Install Steps:
Step 1 Install PHP pecl and pear commands:
sudo apt install php-pear
Step 2 Install librdkafka
sudo apt-get install -y librdkafka-dev
Step 3 Install PECL-package
sudo pecl install rdkafka
Step4 Enable PHP-extension in PHP config. Add to php.ini
sudo nano /etc/php/7.4/cli/php.ini
extension=rdkafka.so
Step 4 Restart apache server
sudo service apache2 restart
Solution 2
because you need another package librdkafka,you should install librdkafka first
- $ git clone https://github.com/edenhill/librdkafka.git
- $ cd librdkafka
- $ ./configure
- $ make && make install
this way can resolve your problem
Solution 3
For Linux Debian Stretch (9.13) actual flow is:
-
Install PHP
pecl
andpear
commands:sudo apt install php-pear
FYI: Depends on your installed PHP version you may need to use concrete version package. For example:
php7.2-pear
. -
Add backports repository. Current ext-rdkafka depends on
librdkafka
version 0.11.0 or greater. So follow official instructions, but usestretch-backports
. -
Install
librdkafka-dev
package from backports:sudo apt -t stretch-backports install librdkafka-dev
-
Update apt:
sudo apt update
-
Install PECL-package:
sudo pecl install rdkafka
-
Enable PHP-extension in PHP config. Add to
php.ini
:extension=rdkafka.so
FYI: You need to restart
php-fpm
service to apply new config params.
Related videos on Youtube
Aviral Srivastava
Updated on May 28, 2022Comments
-
Aviral Srivastava almost 2 years
This is the extension that I am trying to install: https://github.com/EVODelavega/phpkafka
The messages passed to the queue should be in JSON format.
Currently, I am getting installation errors: 1. The instructions ask me to install librdkafka. 2. The installation link for the above step is this. I am unable to install using the 1st and 4th method. This is the error:
checking for librdkafka/rdkafka.h" in default path... not found configure: error: Please reinstall the rdkafka distribution
-
Aviral Srivastava over 6 yearsE: Unable to locate package librdkafka
-
Aviral Srivastava over 6 yearsIf you open the link of the extension that I am talking about: github.com/EVODelavega/phpkafka It asks me to have librdkafka installed. And I am unable to install that, as stated in the question.