Given you have no rdkafka installed on MacOS:
class "RdKafka\Conf" does not exist
RdKafka\Conf does not exist — the error indicates that the librdkafka library is missing or not found in the default path.
By following 5 steps, you should resolve the installation issue and have the rdkafka extension working on your macOS system.
- Install librdkafka Using Homebrew
- Verify the Installation Path
- Install the rdkafka PHP Extension via PECL
- Enable the Extension in PHP
- Verify the rdkafka Extension Loading
1. Install librdkafka Using Homebrew
First, ensure that librdkafka is installed on your system. You can use Homebrew to install librdkafka:
brew install librdkafka
This command installs librdkafka and places its files in the appropriate directories
2. Verify the Installation Path
After installation step 1, verify the path where librdkafka is installed. Typically, Homebrew installs libraries in /usr/local/Cellar/ or /opt/homebrew. Check the exact path using:
brew --prefix librdkafka
This command will display the installation path, which you'll use in the next third rdkafka PHP ext installation step.
% brew --prefix librdkafka /opt/homebrew/opt/librdkafka
3. Install the rdkafka PHP Extension via PECL
With librdkafka installed, proceed to install the rdkafka PHP extension using PECL. During the installation, specify the path to librdkafka if it's not automatically detected:
pecl install rdkafka
If the installer prompts for the librdkafka installation path, provide the path obtained from the previous step (do not use autodetect if it fails).
librdkafka installation path? [autodetect] : /opt/homebrew/opt/librdkafka

4. Enable the Extension in PHP
After successful installation, enable the rdkafka extension by adding the following line to your php.ini file:
extension=rdkafka.so
Usually you do not need to add ext rdkafka.so manually because it's done automatically in the third installation via pecl step. Look at the end of output.
Locate your php.ini file, typically found in /etc/php.ini or /usr/local/etc/php.ini, and add the line above.
% php --ini Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.2 Loaded Configuration File: /opt/homebrew/etc/php/8.2/php.ini Scan for additional .ini files in: /opt/homebrew/etc/php/8.2/conf.d Additional .ini files parsed: /opt/homebrew/etc/php/8.2/conf.d/99-kafka.ini, /opt/homebrew/etc/php/8.2/conf.d/99-xdebug.ini, /opt/homebrew/etc/php/8.2/conf.d/enable-apc-cli.ini, /opt/homebrew/etc/php/8.2/conf.d/ext-imagick.ini, /opt/homebrew/etc/php/8.2/conf.d/ext-memcached.ini, /opt/homebrew/etc/php/8.2/conf.d/ext-opcache.ini % cat /opt/homebrew/etc/php/8.2/php.ini | grep kafka extension="rdkafka.so"
5. Verify the rdkafka Extension Loading
Restart your web server or PHP-FPM to apply the changes. For cli commands, new extenstion will be applied immediately.
Verify that the rdkafka extension is loaded by running php -m
.
If the extension is properly installed and enabled, this command will display rdkafka in the list of loaded modules.
php -m | grep rdkafka rdkafka
Now verify in your code if class "RdKafka\Conf" exists. Now RdKafka should be here.