PHP extensions (like `mongodb`) is not loading for a specific PHP version (e.g., 8.1) enabled by Laravel Herd on macOS?

82 views Asked by At

I'm using Laravel Herd on macOS with multiple PHP versions managed by Herd (7.4, 8.1, 8.2, 8.3). I verified that PHP 8.1 is active using php -v.

Following the Herd documentation for adding extensions (https://herd.laravel.com/docs/1/advanced-usage/additional-extensions), I installed the mongodb extension using brew install php and sudo pecl install mongodb.

I found mongodb.so in two locations:

  • /opt/homebrew/lib/php/pecl/20230831/mongodb.so
  • /opt/homebrew/Cellar/php/8.3.4/pecl/20230831/mongodb.so

However, upon installation, the extension line extension=/opt/homebrew/lib/php/pecl/20230831/mongodb.so was automatically added to the Herd php.ini for the 8.3 version. And mongodb extension is showing fine on php 8.3 nad listed after running php -m, even though the active version is php 8.1.

As I need the extension on php 8.1, When I manually added the same line to the Herd php.ini for the 8.1 version, I encountered the error:

Warning: PHP Startup: Unable to load dynamic library 
'/opt/homebrew/lib/php/pecl/20230831/mongodb.so'

Can anyone give some idea on the recommended approach to install php extension for individual php version enabled by laravel herd?

1

There are 1 answers

0
b126 On

Each version of PHP requires its own extension versions. The same version of a module can work very well on PHP 8.1 and not on PHP 8.3.

You must therefore download the appropriate version specific to your PHP 8.1.

Check the MongoDB compatibility tables depending on your version of PHP and MongoDB.