Cron job Failed to connect to the database; could not find driver

Nextcloud version: 19.0.0
Operating system and version: Ubuntu 20.04
Reverse proxy: Traefik 2.0.7
PHP version : PHP 7.4.3

The issue you are facing:
Cron job failing with following message in log

Exception":“Doctrine\DBAL\DBALException”,“Message”:“Failed to connect to the database: An exception occurred in driver: could not find driver”

The output of your Nextcloud log in Admin > Logging:

{
  "reqId": "0e6FVUbaKsITMqW00kow",
  "level": 3,
  "time": "2020-06-07T16:10:01+00:00",
  "remoteAddr": "",
  "user": "--",
  "app": "cron",
  "method": "",
  "url": "--",
  "message": {
    "Exception": "Doctrine\\DBAL\\DBALException",
    "Message": "Failed to connect to the database: An exception occurred in driver: could not find driver",
    "Code": 0,
    "Trace": [
      {
        "file": "/data/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php",
        "line": 889,
        "function": "connect",
        "class": "OC\\DB\\Connection",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/DB/Connection.php",
        "line": 194,
        "function": "executeQuery",
        "class": "Doctrine\\DBAL\\Connection",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php",
        "line": 200,
        "function": "executeQuery",
        "class": "OC\\DB\\Connection",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php",
        "line": 216,
        "function": "execute",
        "class": "Doctrine\\DBAL\\Query\\QueryBuilder",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/AppConfig.php",
        "line": 331,
        "function": "execute",
        "class": "OC\\DB\\QueryBuilder\\QueryBuilder",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/AppConfig.php",
        "line": 109,
        "function": "loadConfigValues",
        "class": "OC\\AppConfig",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/AppConfig.php",
        "line": 287,
        "function": "getApps",
        "class": "OC\\AppConfig",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/legacy/OC_App.php",
        "line": 883,
        "function": "getValues",
        "class": "OC\\AppConfig",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/Server.php",
        "line": 662,
        "function": "getAppVersions",
        "class": "OC_App",
        "type": "::"
      },
      {
        "file": "/data/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php",
        "line": 118,
        "function": "OC\\{closure}",
        "class": "OC\\Server",
        "type": "->",
        "args": [ "*** sensitive parameters replaced ***" ]
      },
      {
        "file": "/data/nextcloud/lib/private/ServerContainer.php",
        "line": 124,
        "function": "offsetGet",
        "class": "Pimple\\Container",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/Server.php",
        "line": 1699,
        "function": "query",
        "class": "OC\\ServerContainer",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/Server.php",
        "line": 853,
        "function": "getMemCacheFactory",
        "class": "OC\\Server",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php",
        "line": 118,
        "function": "OC\\{closure}",
        "class": "OC\\Server",
        "type": "->",
        "args": [ "*** sensitive parameters replaced ***" ]
      },
      {
        "file": "/data/nextcloud/lib/private/ServerContainer.php",
        "line": 124,
        "function": "offsetGet",
        "class": "Pimple\\Container",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",
        "line": 163,
        "function": "query",
        "class": "OC\\ServerContainer",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php",
        "line": 114,
        "function": "OC\\AppFramework\\Utility\\{closure}",
        "class": "OC\\AppFramework\\Utility\\SimpleContainer",
        "type": "->",
        "args": [ "*** sensitive parameters replaced ***" ]
      },
      {
        "file": "/data/nextcloud/lib/private/ServerContainer.php",
        "line": 124,
        "function": "offsetGet",
        "class": "Pimple\\Container",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/Server.php",
        "line": 1889,
        "function": "query",
        "class": "OC\\ServerContainer",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/legacy/OC_App.php",
        "line": 347,
        "function": "getAppManager",
        "class": "OC\\Server",
        "type": "->"
      },
      {
        "file": "/data/nextcloud/lib/private/legacy/OC_App.php",
        "line": 114,
        "function": "getEnabledApps",
        "class": "OC_App",
        "type": "::"
      },
      {
        "file": "/data/nextcloud/lib/base.php",
        "line": 647,
        "function": "loadApps",
        "class": "OC_App",
        "type": "::"
      },
      {
        "file": "/data/nextcloud/lib/base.php",
        "line": 1090,
        "function": "init",
        "class": "OC",
        "type": "::"
      },
      {
        "file": "/data/nextcloud/cron.php",
        "line": 42,
        "args": [ "/data/nextcloud/lib/base.php" ],
        "function": "require_once"
      }
    ],
    "File": "/data/nextcloud/lib/private/DB/Connection.php",
    "Line": 67,
    "CustomMessage": "--"
  },
  "userAgent": "--",
  "version": "19.0.0.12",
  "id": "5edd1484087e9"
}

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

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'instanceid' => 'oc1s4l7u52i8',
  'passwordsalt' => '+',
  'secret' => '',
  'trusted_domains' =>
  array (
    0 => 'cloud.example.com',
    1 => '192.168.1.5',
    2 => '172.18.0.2',
  ),
  'trusted_proxies' =>
  array (
    0 => '192.168.1.5',
    1 => 'cloud.example.com',
    2 => '172.18.0.2',
  ),
  'overwriteprotocol' => 'https',
  'forwarded-for-headers' =>
  array (
    0 => 'X-Forwarded-For',
    1 => 'HTTP_X_FORWARDED_FOR',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '19.0.0.12',
  'overwrite.cli.url' => 'https://cloud.example.com',
  'dbname' => 'nextcloud',
  'dbhost' => 'database',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '',
  'installed' => true,
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' =>
  array (
    0 => '',
    1 => 'admin',
  ),
  'twofactor_enforced_excluded_groups' =>
  array (
  ),
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'ssl',
  'mail_sendmailmode' => 'smtp',
  'maintenance' => false,
  'loglevel' => 2,
  'mail_from_address' => 'admin',
  'mail_domain' => 'example.com',
  'mail_smtphost' => 'smtp..',
  'mail_smtpport' => '',
  'mail_smtpauth' => 1,
  'mail_smtpname' => '@example.com',
  'mail_smtppassword' => '',
);

I have setup Nextcloud from docker compose using https://github.com/JoshBlades/ncbuilder/blob/master/docker-compose.yml

1 Like