Mongodb.so will not load with PHP 8.1 on Ubuntu 22.04

Has anyone successfully installed PHP8.1 with the mongodb.so driver in linux?
I am using Ubuntu 22.04, which is running flawlessly.

1… I have installed mongodb, which works as advertised using the mongosh shell.
2… PHP is installed using the recommended installation process.
3… The mongodb driver is installed through pear(PECL)
4… I have verified that mongodb.so is actually in folder /usr/lib/php/20210902
4… I have added extension=mongodb.so to the php.ini file which is located in /etc/php/8.1/apache2/
5… I have added the extension dir /usr/lib/php/20210902, which isn’t supposed to be necessary, but I did it anyway.

Both of the paths above are exactly the same as reported in phpinfo.php

When I verify my installation using php -m, I get the following error

PHP Startup: Unable to load dynamic library ‘mongodb.so’ (tried: /usr/lib/php7/modules/mongodb.so (/usr/lib/php7/modules/mongodb.so: undefined symbol: ns_parserr), /usr/lib/php7/modules/mongodb.so.so (/usr/lib/php7/modules/mongodb.so.so: cannot open shared object file: No such file or directory))

This is the installation process I have used.
sudo apt install apache2
sudo apt install php

INSTALL MONGODB EXTENSION FOR PHP

sudo apt install php-dev php-pear
sudo apt -y install php-mongodb

You don’t show yourself installing the MongoDB PHP Extension via sudo pecl install mongodb

I see where I installed it incorrecrly. re-installed with sudo pecl install mongodb. Still will not connect.
I have tried new mongodbClient(‘localhost:27017’)
I have tried new mongodb\driver\manager(‘localhost:27017’)
both throw this err recorder in apache2 error log
Uncaught Error: Class ‘MongoDB\Driver\Manager’ not found
mongodb.so is in the folder /usr/lib/php/20210902
I have 2 php.ini /etc/php/8.1/apache2/php.ini – /etc/php/8.1/cli/php.ini and the extension is loaded in both. the one in /cli is the loaded file.
php -m verifies that the extension is loaded and phpinfo verifies that mongodb is loaded

I am at an impass. I can’t think of anything else.

You have to have the vendor stuff at hand, e…g, require_once getenv('DOCUMENT_ROOT') . '/../vendor/autoload.php'; … you’re not loading the MongoDB library on top of the extension.

$ php -a
Interactive shell

php > require_once('vendor/autoload.php');
php > $x = new \MongoDB\Client('mongodb://localhost');
php > var_dump($x);
object(MongoDB\Client)#3 (4) {
  ["manager"]=>
  object(MongoDB\Driver\Manager)#2 (2) {
    ["uri"]=>
    string(19) "mongodb://localhost"
    ["cluster"]=>
    array(0) {
    }
  }
  ["uri"]=>
  string(19) "mongodb://localhost"
  ["typeMap"]=>
  array(3) {
    ["array"]=>
    string(23) "MongoDB\Model\BSONArray"
    ["document"]=>
    string(26) "MongoDB\Model\BSONDocument"
    ["root"]=>
    string(26) "MongoDB\Model\BSONDocument"
  }
  ["writeConcern"]=>
  object(MongoDB\Driver\WriteConcern)#6 (0) {
  }
}
php >

When you have multiple php.ini files, you can create a PHP info file, and output the current PHP configuration to verify which version is active, and which php.ini file is being used.
https://www.php.net/manual/en/function.phpinfo.php

It would show up like this, for example:
Loaded Configuration File C:\SOME_PATH\bin\php\php-7.4.30-Win32-vc15-x64\php.ini

When you search for “MongoDB” in the page, there’s a whole section that shows if MongoDB is active, and which version of the driver is loaded (or not).

if you have a file named mongodb.ini in the route /etc/php/8.1/mods-available whit the content “extension=mongodb.so”, you can tried comment this line, this works fine for me in php 8.1 and mongodb extensión 1.14.2.