[SOLVED] After Debian 11 upgrade "Failed to connect to the database..."

I am just a home user of nextcloud but I’ve been unable to get any help on solving the “Failed to connect to database” problem below.

[/details]

Nextcloud version (eg, 20.0.5): 23.0.2
Operating system and version (eg, Ubuntu 20.04): Debian 11
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.52-1
PHP version (eg, 7.4): default is 8.1.1 (although I force php 8.0 and 7.4 when running commands) I have now changed my system default PHP to 8.0.14 with the same results

The issue you are facing:
Database not connecting. Any attempt to run occ command or cron.php results in
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:87

I have tried with various php versions all with the same problem

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. run any occ command
  2. try to manuall run cron.php

The output of your Nextcloud log in Admin > Logging:

OCP\AppFramework\Db\DoesNotExistException: FileInfo not found

    /var/www/nextcloud/apps/duplicatefinder/lib/Service/FileInfoService.php - line 88:

    OCA\DuplicateFinder\Db\FileInfoMapper->find()

    /var/www/nextcloud/apps/duplicatefinder/lib/Listener/FilesytemListener.php - line 54:

    OCA\DuplicateFinder\Service\FileInfoService->find()

    /var/www/nextcloud/lib/private/EventDispatcher/ServiceEventListener.php - line 87:

    OCA\DuplicateFinder\Listener\FilesytemListener->handle()

    /var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 251:

    OC\EventDispatcher\ServiceEventListener->__invoke()

    /var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 73:

    Symfony\Component\EventDispatcher\EventDispatcher->callListeners()

    /var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php - line 88:

    Symfony\Component\EventDispatcher\EventDispatcher->dispatch()

    /var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php - line 100:

    OC\EventDispatcher\EventDispatcher->dispatch()

    /var/www/nextcloud/lib/private/Files/Node/HookConnector.php - line 194:

    OC\EventDispatcher\EventDispatcher->dispatchTyped()

    /var/www/nextcloud/lib/private/legacy/OC_Hook.php - line 106:

    OC\Files\Node\HookConnector->postRename()

    /var/www/nextcloud/lib/private/Files/View.php - line 861:

    OC_Hook::emit()

    /var/www/nextcloud/apps/dav/lib/Connector/Sabre/Directory.php - line 442:

    OC\Files\View->rename()

    /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Tree.php - line 160:

    OCA\DAV\Connector\Sabre\Directory->moveInto()

    /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php - line 612:

    Sabre\DAV\Tree->move()

    /var/www/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php - line 89:

    Sabre\DAV\CorePlugin->httpMove()

    /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 472:

    Sabre\DAV\Server->emit()

    /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 253:

    Sabre\DAV\Server->invokeMethod()

    /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 321:

    Sabre\DAV\Server->start()

    /var/www/nextcloud/apps/dav/lib/Server.php - line 339:

    Sabre\DAV\Server->exec()

    /var/www/nextcloud/apps/dav/appinfo/v2/remote.php - line 35:

    OCA\DAV\Server->exec()

    /var/www/nextcloud/remote.php - line 166:

    require_once("/var/www/ne ... p")

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => '',
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' => 
  array (
    0 => 'cloud.xxxxxx.com',
    1 => '192.168.1.23',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '23.0.2.1',
  'overwrite.cli.url' => 'https://cloud.xxxxxx.com',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'xxxxxxx',
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'updater.secret' => '',
  'mail_domain' => 'xxxxxxx.com',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'admin',
  'mail_smtphost' => '127.0.0.1',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'default_phone_region' => 'US',
);

The output of your Apache/nginx/system log in /var/log/____:

[Tue Mar 01 00:00:02.982984 2022] [mpm_prefork:notice] [pid 874] AH00163: Apache/2.4.52 (Debian) mpm-itk/2.4.7-04 OpenSSL/1.1.1k configured -- resuming normal operations
[Tue Mar 01 00:00:02.983008 2022] [core:notice] [pid 874] AH00094: Command line: '/usr/sbin/apache2'
[Tue Mar 01 10:21:58.597338 2022] [access_compat:error] [pid 665862] [client 75.146.113.101:37856] AH01797: client denied by server configuration: /var/www/nextcloud/data/.ocdata
[Tue Mar 01 10:58:08.084845 2022] [access_compat:error] [pid 666581] [client 75.146.113.101:38248] AH01797: client denied by server configuration: /var/www/nextcloud/data/.ocdata

this could be a real problem since it’s said that no NC-version so far would work with php 8.1+ Try downgrading to 8.0 and make sure that your server really uses it.

1 Like

Thank you but I do force php8.0 and 7.4 when running the commands (sudo php8.0 occ…) . I’ve edited the version in my system info above to reflect this.

Debian 11 is Debian Bullseye.
Debian 11 uses PHP 7.4
Debian 11 uses Apache2 2.4.51
Also it uses older MariaDB, …

I think you have installed Debian 12 Bookworm (Testing).
Please reinstall Debian 11. Debian 12 is not supported (yet).

Also you can control or post your sources.list, /etc/issue and uname -a to verify the installed version. I think it is not possible to downgrade to Debian 11. I think you must reinstall.

https://www.howtoforge.com/how-to-install-nextcloud-on-debian-11/

3 Likes
  1. @devnull is right and you probably should use debian stable.

  2. If you do use debain stable with either debian-backports or a 3rd party repo enabled in order to install newer PHP versions, I would still not recommend installing multiple PHP versions at the same time, except you absolutly have to, because some other app on your server needs another PHP version than the one you want to use for Nextcloud. If you for example want to use PHP8.0, remove the other versions: apt remove php8.1* php7.4*

  3. Make sure that all the required php packages / modules are installed in the version you want to use, like for example the “php-mysql” package. You can find an overview of the required modules in the Nextcloud admin Documentation.

  4. Every version of PHP has it’s own configuration files in /etc/php/7.4/, ../8.0/ etc. So changes in the php.ini files must be made again for a different PHP version.

Hope that helps

3 Likes

Thank you for your help. Everything is back up and running as expected. I do have Debian 11 installed, however in the previous install of Debian 10 I apparently added a third party repository including PHP8 for an application dependency. That third party repo followed me to Debian 11 :worried:
I followed your advice and removed that repo, removed all PHP versions other than the default of 7.4 and all is well again.

Thank you

3 Likes

Thank you for your help

2 Likes