9-BoNUS
admin
Rdkafka Install Php8.2

Befire installation

  • apt list --upgradable # check for php8.3 version installed
  • apt remove php8.3-dev php8.3-test... # uninstall all php8.2 extension so that it wll not conflict to php8.2
  • apt autoremove

#To start fresh and install the rdkafka extension for PHP 8.2 only, while ensuring that PHP 8.3 is not affected, follow these steps carefully. I'll also include verification steps after each part.

Steps for Fresh Installation of rdkafka Extension for PHP 8.2 (CLI and FPM)

1. Remove any previous rdkafka installations

We will first remove any existing configurations or installations related to the rdkafka extension.

# Remove the current rdkafka.so files
sudo rm -f /usr/lib/php/8.2/cli/rdkafka.so
sudo rm -f /usr/lib/php/8.2/fpm/rdkafka.so
sudo rm -f /etc/php/8.2/cli/conf.d/20-rdkafka.ini
sudo rm -f /etc/php/8.2/fpm/conf.d/20-rdkafka.ini

2. Install dependencies

We need to install the required libraries and tools for building PHP extensions and Kafka support.

# Install build dependencies
sudo apt update
sudo apt install -y php8.2-cli php8.2-dev php8.2-fpm build-essential librdkafka-dev
 
# Install pecl if not already installed
sudo apt install -y php-pear

3. Install the rdkafka extension via PECL for PHP 8.2

Use the PECL command to install the rdkafka extension. Since your server has both PHP 8.2 and PHP 8.3, we will ensure to install for PHP 8.2 specifically.

# Install rdkafka extension for PHP 8.2
sudo pecl install rdkafka

4. Enable the rdkafka extension in PHP 8.2 for CLI and FPM

Once the extension is installed, we need to enable it for both PHP 8.2 CLI and FPM.

# Enable rdkafka extension for CLI
echo "extension=rdkafka.so" | sudo tee /etc/php/8.2/cli/conf.d/20-rdkafka.ini
 
# Enable rdkafka extension for FPM
echo "extension=rdkafka.so" | sudo tee /etc/php/8.2/fpm/conf.d/20-rdkafka.ini

5. Verify the installation for CLI and FPM

After installation, let's verify that rdkafka is loaded correctly for both PHP CLI and PHP-FPM.

# Verify PHP CLI
php -m | grep rdkafka
 
# Verify PHP-FPM
sudo systemctl restart php8.2-fpm
 
# Verify PHP-FPM
sudo php-fpm8.2 -m | grep rdkafka

6. Check PHP version

Make sure the correct version of PHP is being used for CLI and FPM.

# Check PHP CLI version
php -v
 
# Check PHP-FPM version
php-fpm8.2 -v

7. Restart PHP-FPM and Apache/Nginx (if applicable)

After enabling the extension, restart PHP-FPM and web server (if you use Apache or Nginx) to make sure the extension is loaded correctly in the web environment.

# Restart PHP-FPM for PHP 8.2
sudo systemctl restart php8.2-fpm
 
# Restart web server (e.g., Nginx or Apache)
sudo systemctl restart nginx  # if using Nginx
# or
sudo systemctl restart apache2  # if using Apache

8. Verify the rdkafka extension in your web environment

Now, verify if the rdkafka extension is working with a simple PHP script.

Create a PHP file to check the loaded modules:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php

Visit http://your_server_ip/phpinfo.php and look for rdkafka in the output to confirm it is loaded.

Summary of the Steps

  1. Remove previous installations of rdkafka.
  2. Install required dependencies and PHP 8.2 development packages.
  3. Install rdkafka extension using pecl.
  4. Enable the extension in the appropriate .ini files for CLI and FPM.
  5. Restart PHP-FPM and web server.
  6. Verify the installation with php -m and phpinfo().

Final Verification

After following the steps above, you should see the rdkafka extension listed when running php -m, and it should be active both in the CLI and FPM contexts. If everything is successful, the warning should be gone and the extension will be properly loaded. Let me know how it goes!


💬 Need a Quick Summary?

Hey! Don't have time to read everything? I get it. 😊
Click below and I'll give you the main points and what matters most on this page.
Takes about 5 seconds • Uses Perplexity AI