This guide explains how to install and configure the rdkafka extension in PHP 8.3, which is a required dependency for the php-kafka-client library. This setup enables interaction with Apache Kafka in your PHP applications.
First, install the librdkafka library, which is required for the extension to work:
sudo apt install librdkafka-dev
Now, install the rdkafka extension using PECL:
sudo pecl install rdkafka
After installation, add the extension to PHP by creating a configuration file:
echo "extension=rdkafka.so" | sudo tee /etc/php/8.3/mods-available/rdkafka.ini
Now, enable the extension with:
sudo phpenmod -v 8.3 rdkafka
To check if rdkafka is correctly installed, run:
php -m | grep rdkafka
If the extension is installed correctly, the command above should display rdkafka in the output.
Now your PHP environment is ready to use php-kafka-client to interact with Apache Kafka! 🚀