Alex
Alex

Reputation: 183

Got error 'PHP message: PHP Fatal error: Uncaught Error: Class 'MongoClient' not found in /var/www/html/dbtest.php:5

I've installed MongoDB on my server and I'm trying to run this script:

<?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);

This is the error I get: Got error 'PHP message: PHP Fatal error: Uncaught Error: Class 'MongoClient' not found in /var/www/html/dbtest.php:5

My Apache server uses /etc/php/7.3/fpm/php.ini according to phpinfo();.

Adding extension=mongodb.so to the php.ini file is useless.

Upvotes: 0

Views: 517

Answers (1)

Alex
Alex

Reputation: 183

The solution was to restart php-fpm.

In my case I have PHP version 7.3 installed, so I needed to run this command: sudo service php7.3-fpm restart

Upvotes: 1

Related Questions