[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.


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:


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


    /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!):

$CONFIG = array (
  'instanceid' => '',
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' => 
  array (
    0 => 'cloud.xxxxxx.com',
    1 => '',
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '',
  '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' => '',
  '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] 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] 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.


  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


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


Thank you for your help