Error with PHP 8.1 MongoDB driver on Ubuntu 22.04

3.4k Views Asked by At

(Note: I'm running Ubuntu server 22.04 with PHP 8.1)

I have followed what I assume to be the standard procedure for setting up PHP with MongoDB on Ubuntu systems, that being:

  • install php-fpm
  • install php-pear, php-dev and php-mongodb
  • pecl install mongodb
  • add extension=mongodb.so to /etc/php/8.1/fpm/php.ini
  • reload and restart php8.1-fpm
  • install composer & composer require mongodb/mongodb in project root

However, when I run any kind of PHP code that makes use of the MongoDB driver (required with require_once __DIR__ . "/vendor/autoload.php";); I get the following error: php: symbol lookup error: /usr/lib/php/20210902/mongodb.so: undefined symbol: ns_initparse.

I have not found anybody else with a similar issue, am I missing some new required step, or should I just drop back down to Ubuntu 20.04 with PHP 7.4 (which works on my development machine running Linux Mint 20.3). Thank you in advance.

1

There are 1 best solutions below

0
Dara Vichit On

I also face this problem, I sovle it following below step

Make sure you has been install php mongodb

sudo apt install php8.1-mongodb

To do this in Ubuntu, you'll need the php-pear plugin and php-dev

sudo apt install php-dev php-pear

then you can run:

sudo pecl install mongodb

then add "extension=mongodb.so" to php.ini

then restart your php service

service php8.1-fpm restart

or

service php-fpm restart

Hope can help you!!!

ref : https://www.php.net/manual/en/mongodb.installation.pecl.php#125027