How do I install an extension of Kafka for PHP?

13,689

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

this way can resolve your problem

Solution 3

For Linux Debian Stretch (9.13) actual flow is:

  1. Install PHP pecl and pear 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.

  2. Add backports repository. Current ext-rdkafka depends on librdkafka version 0.11.0 or greater. So follow official instructions, but use stretch-backports.

  3. Install librdkafka-dev package from backports:

    sudo apt -t stretch-backports install librdkafka-dev
    
  4. Update apt:

    sudo apt update
    
  5. Install PECL-package:

    sudo pecl install rdkafka
    
  6. 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.

Share:
13,689

Related videos on Youtube

Aviral Srivastava
Author by

Aviral Srivastava

Updated on May 28, 2022

Comments

  • Aviral Srivastava
    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
    Aviral Srivastava over 6 years
    E: Unable to locate package librdkafka
  • Aviral Srivastava
    Aviral Srivastava over 6 years
    If 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.