Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /var/www/nextcloud/lib/private/DB/Connection.php:139

Hallo Nextcloud Forum,

ich habe heute von NC 27 auf NC 28 über den Browser geupdatet.
Nach dem Update, habe ich in der Webübersicht geschaut ob es Fehler gibt.
Es gab nur eine:

In der Datenbank fehlen einige Indizes. Auf Grund der Tatsache, dass das Hinzufügen von Indizes in großen Tabellen einige Zeit in Anspruch nehmen kann, wurden diese nicht automatisch erzeugt. Durch das Ausführen von "occ db:add-missing-indices" können die fehlenden Indizes manuell hinzugefügt werden, während die Instanz weiter läuft. Nachdem die Indizes hinzugefügt wurden, sind Anfragen auf die Tabellen normalerweise schneller. Fehlende optionaler Index "mail_messages_msgid_idx" in der Tabelle "mail_messages".

Normalerweise macht man ja bei “missing-indices”:

sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices

Bei mir kam aber nun der Fehler:

An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /var/www/nextcloud/lib/private/DB/Connection.php:139
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1654): OC\DB\Connection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1081): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /var/www/nextcloud/lib/private/DB/Connection.php(261): Doctrine\DBAL\Connection->executeQuery()
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(337): OC\DB\Connection->executeQuery()
#4 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(377): Doctrine\DBAL\Query\QueryBuilder->executeQuery()
#5 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(280): Doctrine\DBAL\Query\QueryBuilder->execute()
#6 /var/www/nextcloud/lib/private/AppConfig.php(418): OC\DB\QueryBuilder\QueryBuilder->execute()
#7 /var/www/nextcloud/lib/private/AppConfig.php(184): OC\AppConfig->loadConfigValues()
#8 /var/www/nextcloud/lib/private/AppConfig.php(374): OC\AppConfig->getApps()
#9 /var/www/nextcloud/lib/private/App/AppManager.php(128): OC\AppConfig->getValues()
#10 /var/www/nextcloud/lib/private/App/AppManager.php(149): OC\App\AppManager->getInstalledAppsValues()
#11 /var/www/nextcloud/lib/private/legacy/OC_App.php(231): OC\App\AppManager->getInstalledApps()
#12 /var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php(90): OC_App::getEnabledApps()
#13 /var/www/nextcloud/lib/base.php(700): OC\AppFramework\Bootstrap\Coordinator->runInitialRegistration()
#14 /var/www/nextcloud/lib/base.php(1200): OC::init()
#15 /var/www/nextcloud/console.php(48): require_once('...')
#16 /var/www/nextcloud/occ(11): require_once('...')

Ich habe mir dementsprechend ein paar Foren eintrage zum Thema angesehen. Die Lösungen, die vorgeschlagen wurden, haben aber nicht funktioniert.

Meine Dispro ist “Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-92-generic x86_64)”
Meine PHP module sind von: PHP 8.2

Kann mir jemand helfen?

Grüße Julius

Prüf mal, ob das die richtige Version ausgibt. Wenn du mehrere PHP Versionen installiert hast, wird auf CLI manchmal ein andere verwendet, als im web. Ggf. gibt es auch sudo -u www-data php8.2 oder so

Hallo SysKeeper,

hier ist die Ausgabe:

PHP 8.3.2-1+ubuntu22.04.1+deb.sury.org+1 (cli) (built: Jan 20 2024 14:16:40) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.2-1+ubuntu22.04.1+deb.sury.org+1, Copyright (c), by Zend Technologies

Versionen 8.2 und 8.3 ist in /etc/php zu finden.

Dann fehlen dir vermutlich für 8.3 einige Module. Versuch mal ob du 8.2 direkt aufrufen kannst und wiederhole den Befehl

War möglich.
Habe im Zuge mal 8.2 entfernt und alle Module für 8.3 installiert. Habe apache2 gesagt das jetzt php8.3 statt 8.2 nutzen soll.
Wenn ich aber jetzt auf die URL der NC gehe kommt:

<?php
/**
 * @copyright Copyright (c) 2016, ownCloud, Inc.
 *
 * @author Christoph Wurst <christoph@winzerhof-wurst.at>
 * @author Joas Schilling <coding@schilljs.com>
 * @author Jörn Friedrich Dreyer <jfd@butonic.de>
 * @author Lukas Reschke <lukas@statuscode.ch>
 * @author Morris Jobke <hey@morrisjobke.de>
 * @author Robin Appelman <robin@icewind.nl>
 * @author Roeland Jago Douma <roeland@famdouma.nl>
 * @author Sergio Bertolín <sbertolin@solidgear.es>
 * @author Thomas Müller <thomas.mueller@tmit.eu>
 * @author Vincent Petry <vincent@nextcloud.com>
 *
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 *
 */
require_once __DIR__ . '/lib/versioncheck.php';

use OCP\Security\Bruteforce\MaxDelayReached;
use Psr\Log\LoggerInterface;

try {
	require_once __DIR__ . '/lib/base.php';

	OC::handleRequest();
} catch (\OC\ServiceUnavailableException $ex) {
	\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
		'app' => 'index',
		'exception' => $ex,
	]);

	//show the user a detailed error page
	OC_Template::printExceptionErrorPage($ex, 503);
} catch (\OCP\HintException $ex) {
	try {
		OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503);
	} catch (Exception $ex2) {
		try {
			\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
				'app' => 'index',
				'exception' => $ex,
			]);
			\OC::$server->get(LoggerInterface::class)->error($ex2->getMessage(), [
				'app' => 'index',
				'exception' => $ex2,
			]);
		} catch (Throwable $e) {
			// no way to log it properly - but to avoid a white page of death we try harder and ignore this one here
		}

		//show the user a detailed error page
		OC_Template::printExceptionErrorPage($ex, 500);
	}
} catch (\OC\User\LoginException $ex) {
	$request = \OC::$server->getRequest();
	/**
	 * Routes with the @CORS annotation and other API endpoints should
	 * not return a webpage, so we only print the error page when html is accepted,
	 * otherwise we reply with a JSON array like the SecurityMiddleware would do.
	 */
	if (stripos($request->getHeader('Accept'), 'html') === false) {
		http_response_code(401);
		header('Content-Type: application/json; charset=utf-8');
		echo json_encode(['message' => $ex->getMessage()]);
		exit();
	}
	OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
} catch (MaxDelayReached $ex) {
	$request = \OC::$server->getRequest();
	/**
	 * Routes with the @CORS annotation and other API endpoints should
	 * not return a webpage, so we only print the error page when html is accepted,
	 * otherwise we reply with a JSON array like the BruteForceMiddleware would do.
	 */
	if (stripos($request->getHeader('Accept'), 'html') === false) {
		http_response_code(429);
		header('Content-Type: application/json; charset=utf-8');
		echo json_encode(['message' => $ex->getMessage()]);
		exit();
	}
	http_response_code(429);
	OC_Template::printGuestPage('core', '429');
} catch (Exception $ex) {
	\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
		'app' => 'index',
		'exception' => $ex,
	]);

	//show the user a detailed error page
	OC_Template::printExceptionErrorPage($ex, 500);
} catch (Error $ex) {
	try {
		\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
			'app' => 'index',
			'exception' => $ex,
		]);
	} catch (Error $e) {
		http_response_code(500);
		header('Content-Type: text/plain; charset=utf-8');
		print("Internal Server Error\n\n");
		print("The server encountered an internal error and was unable to complete your request.\n");
		print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
		print("More details can be found in the webserver log.\n");

		throw $ex;
	}
	OC_Template::printExceptionErrorPage($ex, 500);
}

Ich hatte sowieso vor im Zuge von NC27 auf NC28 auf php8.3 upzudaten.
Kann auch sein das ich voreilig war. Backup ist aber vorhanden.

Das Problem lag daran das PHP8.2 und PHP8.3 gleichzeitig vom System genutzt wurden. Nachdem PHP8.2 entfernt wurde und PHP8.3 mit allen Modulen installiert wurden, konnten die “missing-indices” hinzugefügt werden.

Fazit: kein apt-get update machen und immer im Auge behalten das nur eine PHP-V auf dem Nextcloud-System vorhanden ist.

1 Like

Das PHP8.3 Modul war noch nicht Aktive:

sudo apt update
sudo apt upgrade
sudo apt install ca-certificates apt-transport-https software-properties-common lsb-release -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt install php8.3
sudo a2enmod php8.3
sudo systemctl restart apache2
1 Like

Vielen Dank. Das Entfernen des redundanten PHP-Moduls löste das Problem.