获取错误“PHP message:PHP致命错误:未捕获错误:在/var/www/html/dbtest.PHP:5中找不到类“MongoClient”

获取错误“PHP message:PHP致命错误:未捕获错误:在/var/www/html/dbtest.PHP:5中找不到类“MongoClient”,php,mongodb,Php,Mongodb,我已经在服务器上安装了MongoDB,我正在尝试运行以下脚本: <?php $client = new MongoClient(); $collection = $client->cryptnote->storedMessages; function insertDocument($collection, $id, $telegramuser, $message) { $doc = array( "id" => $id, "te

我已经在服务器上安装了MongoDB,我正在尝试运行以下脚本:

<?php

$client = new MongoClient();
$collection = $client->cryptnote->storedMessages;

function insertDocument($collection, $id, $telegramuser, $message) {
    $doc = array(
        "id" => $id,
        "telegram" => $telegramuser,
        "encrypted" => $message,
    );
    try {
        $collection->insert($doc);
    } catch(Exception $e) {
        echo "Error" . $e;
    }
}

function findDocument($collection, $id){
    return $collection->findOne(["id" => $id]);
}

insertDocument($collection, "test123", "usertest", "message. test.");
$query = findDocument($collection, "test123");
echo "<pre>";
var_dump($query);
这是我得到的错误: 获取错误“PHP message:PHP致命错误:未捕获错误:在/var/www/html/dbtest.PHP:5中找不到类“MongoClient”

根据phpinfo;,我的Apache服务器使用/etc/php/7.3/fpm/php.ini


将extension=mongodb.so添加到php.ini文件是无用的。

解决方案是重新启动php fpm

在我的例子中,安装了PHP 7.3版,因此需要运行以下命令:
sudo服务php7.3-fpm重启

这里有一个解决方案-我这样做了,但它不起作用