I am trying to setup MongoDB for php, when creating wordpress plugin, but get this error: Fatal error : Uncaught Error: Class “MongoDB\Driver\Manager” not found in C:\Users\qhuser\Local Sites\wordpress-with-react\app\public\wp-content\plugins\test\vendor\mongodb\mongodb\src\Client.php:118
Also created test file, with <?php phpinfo() ?> inside, and ran it inside the powershell, did that to confirm that the support for MongoDB is present inside powershell:
I installed the library via the composer require mongodb/mongodb and added the extension manually into the /ext folder inside the /php folder. Also added extension=php_mongodb.dll inside the php.ini file.
Don’t know if this would help, but when I run php -m or php --ri mongodb inside windows powershell I see MongoDB there and the appropriate support, but when I do php_info(), no support is shown inside the wordpress website, for which I am developing the plugin, I suppose it is because php_info() is ran for different enviroment and has nothing to do with the MongoDB setup inside the plugin?
I know it is not only Mongo related, but I wanted to share the solution in case it helps someone else down the line:
When you’re building a website for local development (like I did with Localwp), and you’re enhancing the functionality of the WordPress site (such as adding a custom plugin with the npx create-divi-extension command), it’s essential to ensure that any additional libraries and extensions you include in the custom plugin (like MongoDB in my case) are also supported by the actual Localwp website.
For Windows users, here’s what you need to do: if you add extension=php_mongodb.dll in the php.ini file of the plugin and place the php_mongodb.dll file (with the correct version and type safety) in the /ext folder, which the plugin uses, you also need to add that extension to the appropriate php.ini & /ext folders of the Localwp website. These folders can be found here: C:\Users\...\AppData\Roaming\Local\lightning-services\ & C:\Users\...\AppData\Roaming\Local\run\.