Error 500 - Failed to connect to the database: exception occurred in driver could not find driver

Nextcloud version (eg, 18.0.2): 20.0.2.2
Operating system and version (eg, Ubuntu 20.04): Raspbian Buster
Apache or nginx version (eg, Apache 2.4.25): 2.4.38
PHP version (eg, 7.1): 7.3.19-1

The issue you are facing:
Trying to access Nextcloud via my browser, I see a white screen saying “Internal Server Error”. When trying to sync via Davx5, I see an Error 500.

Is this the first time you’ve seen this error? (Y/N): Yes. I installed Nextcloud 2 days ago. The error suddenly started happening last night, for no apparent reason.

The output of your Nextcloud log in Admin > Logging:

{"reqId":"3Mks0Tcbty9OWY1D9ivC","level":3,"time":"2020-12-01T08:41:12+00:00","remoteAddr":"192.168.1.10","user":"--","app":"remote","method":"GET","url":"/nextcloud/status.php","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":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":1449,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":892,"function":"getWrappedConnection","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/nextcloud/lib/private/DB/Connection.php","line":202,"function":"executeQuery","class":"Doctrine\\DBAL\\Connection","type":"->","args":["SELECT * FROM `oc_appconfig`",[],[],null]},{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php","line":206,"function":"executeQuery","class":"OC\\DB\\Connection","type":"->","args":["SELECT * FROM `oc_appconfig`",[],[]]},{"file":"/var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php","line":217,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/nextcloud/lib/private/AppConfig.php","line":345,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/nextcloud/lib/private/AppConfig.php","line":110,"function":"loadConfigValues","class":"OC\\AppConfig","type":"->","args":[]},{"file":"/var/www/nextcloud/lib/private/AppConfig.php","line":301,"function":"getApps","class":"OC\\AppConfig","type":"->","args":[]},{"file":"/var/www/nextcloud/lib/private/legacy/OC_App.php","line":949,"function":"getValues","class":"OC\\AppConfig","type":"->","args":[false,"installed_version"]},{"file":"/var/www/nextcloud/lib/private/Server.php","line":668,"function":"getAppVersions","class":"OC_App","type":"::","args":[]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php","line":155,"function":"OC\\{closure}","class":"OC\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php","line":118,"function":"OC\\AppFramework\\Utility\\{closure}","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php","line":122,"function":"offsetGet","class":"Pimple\\Container","type":"->","args":["OC\\Memcache\\Factory"]},{"file":"/var/www/nextcloud/lib/private/ServerContainer.php","line":156,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OC\\Memcache\\Factory",true]},{"file":"/var/www/nextcloud/lib/private/Server.php","line":1677,"function":"query","class":"OC\\ServerContainer","type":"->","args":["OC\\Memcache\\Factory"]},{"file":"/var/www/nextcloud/lib/private/Server.php","line":1017,"function":"getMemCacheFactory","class":"OC\\Server","type":"->","args":[]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php","line":155,"function":"OC\\{closure}","class":"OC\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php","line":118,"function":"OC\\AppFramework\\Utility\\{closure}","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php","line":122,"function":"offsetGet","class":"Pimple\\Container","type":"->","args":["OCP\\Lock\\ILockingProvider"]},{"file":"/var/www/nextcloud/lib/private/ServerContainer.php","line":156,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OCP\\Lock\\ILockingProvider",true]},{"file":"/var/www/nextcloud/lib/private/Server.php","line":1977,"function":"query","class":"OC\\ServerContainer","type":"->","args":["OCP\\Lock\\ILockingProvider"]},{"file":"/var/www/nextcloud/lib/private/Files/View.php","line":118,"function":"getLockingProvider","class":"OC\\Server","type":"->","args":[]},{"file":"/var/www/nextcloud/lib/private/Server.php","line":395,"function":"__construct","class":"OC\\Files\\View","type":"->","args":[]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php","line":155,"function":"OC\\{closure}","class":"OC\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php","line":118,"function":"OC\\AppFramework\\Utility\\{closure}","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php","line":122,"function":"offsetGet","class":"Pimple\\Container","type":"->","args":["OC\\Files\\Node\\HookConnector"]},{"file":"/var/www/nextcloud/lib/private/ServerContainer.php","line":156,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OC\\Files\\Node\\HookConnector",true]},{"file":"/var/www/nextcloud/lib/private/Server.php","line":1324,"function":"query","class":"OC\\ServerContainer","type":"->","args":["OC\\Files\\Node\\HookConnector"]},{"file":"/var/www/nextcloud/lib/base.php","line":595,"function":"boot","class":"OC\\Server","type":"->","args":[]},{"file":"/var/www/nextcloud/lib/base.php","line":1091,"function":"init","class":"OC","type":"::","args":[]},{"file":"/var/www/nextcloud/status.php","line":37,"args":["/var/www/nextcloud/lib/base.php"],"function":"require_once"}],"File":"/var/www/nextcloud/lib/private/DB/Connection.php","Line":72,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Linux) mirall/2.3.3 (Nextcloud)","version":"20.0.2.2"}

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

<?php
$CONFIG = array (
  'instanceid' => 'xxx',
  'passwordsalt' => 'xxx',
  'secret' => 'xxx',
  'trusted_domains' => 
  array (
    0 => '192.168.1.14',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '20.0.2.2',
  'overwrite.cli.url' => 'http://192.168.1.14/nextcloud',
  'dbname' => 'xxx',
  'dbhost' => 'localhost:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'xxx',
  'dbpassword' => 'xxx',
  'installed' => true,
  'app_install_overwrite' => 
  array (
    0 => 'joplin',
  ),
);

The output of your Apache/nginx/system log in /var/log/____: Please see https://pastebin.com/DV6JnN2x

Extra info:

  • Apache seems to be working fine;
  • I tried sudo -u www-data php -i and the PhP info seems all good (at least it corresponds to the php version I get when doing <?php phpinfo(); ?>)

All help would be much appreciated!! :pray:

Although you’ve already check the list of loaded php modules, the error messages indicates that the php cli configuration seems not be configured correctly. You can e.g. test the database access using the following php test script:

<?php

#$dsn = 'mysql:dbname=nextcloud;unix_socket=/run/mysql/102/mysql.sock';
 $dsn = 'mysql:dbname=nextcloud;host=localhost:3306';
 $opt = [
     PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
     PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
     PDO::ATTR_EMULATE_PREPARES   => false,
 ];
$user = '<user>';
$pass = '<pass>';

try {
    $pdo = new PDO($dsn, $user, $pass, $opt);
    $sql = "SHOW TABLES";
    $stmt = $pdo->query($sql);

    print("-start-------------<br>\n");
    while ($row = $stmt->fetch())
    {
        $str = implode($row);
        print($str."<br>\n");
    }
    print("-end---------------<br>\n");
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage() . "\n";
}

?>

Thanks for your reply!

I tried your script, and got this error message: “Connection failed: could not find driver”
It looks like my issue might be related to this one, and/or that one … Maybe I have missing indices?? But I’m still quite confused as to what next steps I should try to figure things out :confused:

So that’s an indication that your problem isn’t specific to Nextcloud and you have a general php module problem. If you’ve executed it using the php cli component and are getting the error. you can use “php -i” to find the configuration files being loaded by the program and “php -m” to check that the php-mysql package/drive has correctly been loaded.

I did php -i and php-m, but it seems all modules are enabled…
The only thing that caught my attention was the disabled Zend OPcache.

Zend OPcache

Opcode Caching => Disabled
Optimization => Disabled
SHM Cache => Enabled
File Cache => Disabled
Startup Failed => Opcode Caching is disabled for CLI

I tried running php -a and print_r(opcache_get_configuration()); to check, and here’s what I got. Not sure if it means anything suspicious?

Array
(
    [directives] => Array
        (
            [opcache.enable] => 1
            [opcache.enable_cli] => 
            [opcache.use_cwd] => 1
            [opcache.validate_timestamps] => 1
            [opcache.validate_permission] => 
            [opcache.validate_root] => 
            [opcache.dups_fix] => 
            [opcache.revalidate_path] => 
            [opcache.log_verbosity_level] => 1
            [opcache.memory_consumption] => 134217728
            [opcache.interned_strings_buffer] => 8
            [opcache.max_accelerated_files] => 10000
            [opcache.max_wasted_percentage] => 0.05
            [opcache.consistency_checks] => 0
            [opcache.force_restart_timeout] => 180
            [opcache.revalidate_freq] => 2
            [opcache.preferred_memory_model] => 
            [opcache.blacklist_filename] => 
            [opcache.max_file_size] => 0
            [opcache.error_log] => 
            [opcache.protect_memory] => 
            [opcache.save_comments] => 1
            [opcache.enable_file_override] => 
            [opcache.optimization_level] => 2147401727
            [opcache.lockfile_path] => /tmp
            [opcache.file_cache] => 
            [opcache.file_cache_only] => 
            [opcache.file_cache_consistency_checks] => 1
            [opcache.file_update_protection] => 2
            [opcache.opt_debug_level] => 0
            [opcache.restrict_api] => 
            [opcache.huge_code_pages] => 
        )

    [version] => Array
        (
            [version] => 7.3.19-1~deb10u1
            [opcache_product_name] => Zend OPcache
        )

    [blacklist] => Array
        (
        )

)

You can compare the value with the ones from the admin guide:

As far as I remember the opcache should be disable for the cli interface to speed-up these commands, by setting “opcache.enable_cli=0”. (I don’t know what the default value is).

Thanks. All my opcache values correspond to the ones recommended in the admin guide - apart from the opcache.memory_consumption data… Why does it show 134217728, when the value in my php.ini is set to 128? And does this matter? (I can’t find anything on this online)

It seems that opcache.enable_cli was already off, but I set the value to 0 in /apache2/php.ini just in case and the result of print_r(opcache_get_configuration()); remains the same. (which makes sense, as the default value appears to be 0!)

Very much scratching my head over this. Should I try reinstalling all PHP packages completely?!

Hi, sorry for hijacking. how do i get this log ??

Btw, i seem to have the same error

Install the Log reader app :wink:

Try sudo nano /your/nextcloud/folder/data/nextcloud.log and if you don’t have the authorization you can do sudo su - to become root first (I had to).

@doncaviare almost the same error as you have? :thinking:

{"reqId":"CMTHqbkJMgmdWdX9ebtI","level":3,"time":"2020-12-01T21:21:46+00:00","remoteAddr":"192.168.1.99","user":"--","app":"index","method":"GET","url":"/","message":{"Exception":"Doctrine\\DBAL\\DBALException","Message":"Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused","Code":0,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":1449,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":892,"function":"getWrappedConnection","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/Connection.php","line":202,"function":"executeQuery","class":"Doctrine\\DBAL\\Connection","type":"->","args":["SELECT * FROM `oc_appconfig`",[],[],null]},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php","line":206,"function":"executeQuery","class":"OC\\DB\\Connection","type":"->","args":["SELECT * FROM `oc_appconfig`",[],[]]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":217,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":345,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":110,"function":"loadConfigValues","class":"OC\\AppConfig","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":301,"function":"getApps","class":"OC\\AppConfig","type":"->","args":[]},{"file":"/var/www/html/lib/private/legacy/OC_App.php","line":949,"function":"getValues","class":"OC\\AppConfig","type":"->","args":[false,"installed_version"]},{"file":"/var/www/html/lib/private/Server.php","line":668,"function":"getAppVersions","class":"OC_App","type":"::","args":[]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":155,"function":"OC\\{closure}","class":"OC\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php","line":118,"function":"OC\\AppFramework\\Utility\\{closure}","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":122,"function":"offsetGet","class":"Pimple\\Container","type":"->","args":["OC\\Memcache\\Factory"]},{"file":"/var/www/html/lib/private/ServerContainer.php","line":156,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OC\\Memcache\\Factory",true]},{"file":"/var/www/html/lib/private/Server.php","line":1677,"function":"query","class":"OC\\ServerContainer","type":"->","args":["OC\\Memcache\\Factory"]},{"file":"/var/www/html/lib/private/Server.php","line":1017,"function":"getMemCacheFactory","class":"OC\\Server","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":155,"function":"OC\\{closure}","class":"OC\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php","line":118,"function":"OC\\AppFramework\\Utility\\{closure}","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":122,"function":"offsetGet","class":"Pimple\\Container","type":"->","args":["OCP\\Lock\\ILockingProvider"]},{"file":"/var/www/html/lib/private/ServerContainer.php","line":156,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OCP\\Lock\\ILockingProvider",true]},{"file":"/var/www/html/lib/private/Server.php","line":1977,"function":"query","class":"OC\\ServerContainer","type":"->","args":["OCP\\Lock\\ILockingProvider"]},{"file":"/var/www/html/lib/private/Files/View.php","line":118,"function":"getLockingProvider","class":"OC\\Server","type":"->","args":[]},{"file":"/var/www/html/lib/private/Server.php","line":395,"function":"__construct","class":"OC\\Files\\View","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":155,"function":"OC\\{closure}","class":"OC\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php","line":118,"function":"OC\\AppFramework\\Utility\\{closure}","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":122,"function":"offsetGet","class":"Pimple\\Container","type":"->","args":["OC\\Files\\Node\\HookConnector"]},{"file":"/var/www/html/lib/private/ServerContainer.php","line":156,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OC\\Files\\Node\\HookConnector",true]},{"file":"/var/www/html/lib/private/Server.php","line":1324,"function":"query","class":"OC\\ServerContainer","type":"->","args":["OC\\Files\\Node\\HookConnector"]},{"file":"/var/www/html/lib/base.php","line":595,"function":"boot","class":"OC\\Server","type":"->","args":[]},{"file":"/var/www/html/lib/base.php","line":1091,"function":"init","class":"OC","type":"::","args":[]},{"file":"/var/www/html/index.php","line":35,"args":["/var/www/html/lib/base.php"],"function":"require_once"}],"File":"/var/www/html/lib/private/DB/Connection.php","Line":72,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36 Edg/87.0.664.41","version":"19.0.1.1"}
{"reqId":"CMTHqbkJMgmdWdX9ebtI","level":3,"time":"2020-12-01T21:21:46+00:00","remoteAddr":"192.168.1.99","user":"--","app":"core","method":"GET","url":"/","message":{"Exception":"Doctrine\\DBAL\\DBALException","Message":"Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused","Code":0,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":1449,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":892,"function":"getWrappedConnection","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/Connection.php","line":202,"function":"executeQuery","class":"Doctrine\\DBAL\\Connection","type":"->","args":["SELECT * FROM `oc_appconfig`",[],[],null]},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php","line":206,"function":"executeQuery","class":"OC\\DB\\Connection","type":"->","args":["SELECT * FROM `oc_appconfig`",[],[]]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":217,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":345,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":110,"function":"loadConfigValues","class":"OC\\AppConfig","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":301,"function":"getApps","class":"OC\\AppConfig","type":"->","args":[]},{"file":"/var/www/html/lib/private/legacy/OC_App.php","line":949,"function":"getValues","class":"OC\\AppConfig","type":"->","args":[false,"installed_version"]},{"file":"/var/www/html/lib/private/Server.php","line":668,"function":"getAppVersions","class":"OC_App","type":"::","args":[]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":155,"function":"OC\\{closure}","class":"OC\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php","line":118,"function":"OC\\AppFramework\\Utility\\{closure}","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":122,"function":"offsetGet","class":"Pimple\\Container","type":"->","args":["OC\\Memcache\\Factory"]},{"file":"/var/www/html/lib/private/ServerContainer.php","line":156,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OC\\Memcache\\Factory",true]},{"file":"/var/www/html/lib/private/Server.php","line":1677,"function":"query","class":"OC\\ServerContainer","type":"->","args":["OC\\Memcache\\Factory"]},{"file":"/var/www/html/lib/private/Server.php","line":1017,"function":"getMemCacheFactory","class":"OC\\Server","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":155,"function":"OC\\{closure}","class":"OC\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php","line":118,"function":"OC\\AppFramework\\Utility\\{closure}","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":122,"function":"offsetGet","class":"Pimple\\Container","type":"->","args":["OCP\\Lock\\ILockingProvider"]},{"file":"/var/www/html/lib/private/ServerContainer.php","line":156,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OCP\\Lock\\ILockingProvider",true]},{"file":"/var/www/html/lib/private/Server.php","line":1977,"function":"query","class":"OC\\ServerContainer","type":"->","args":["OCP\\Lock\\ILockingProvider"]},{"file":"/var/www/html/lib/private/Files/View.php","line":118,"function":"getLockingProvider","class":"OC\\Server","type":"->","args":[]},{"file":"/var/www/html/lib/private/Server.php","line":395,"function":"__construct","class":"OC\\Files\\View","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":155,"function":"OC\\{closure}","class":"OC\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php","line":118,"function":"OC\\AppFramework\\Utility\\{closure}","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php","line":122,"function":"offsetGet","class":"Pimple\\Container","type":"->","args":["OC\\Files\\Node\\HookConnector"]},{"file":"/var/www/html/lib/private/ServerContainer.php","line":156,"function":"query","class":"OC\\AppFramework\\Utility\\SimpleContainer","type":"->","args":["OC\\Files\\Node\\HookConnector",true]},{"file":"/var/www/html/lib/private/Server.php","line":1324,"function":"query","class":"OC\\ServerContainer","type":"->","args":["OC\\Files\\Node\\HookConnector"]},{"file":"/var/www/html/lib/base.php","line":595,"function":"boot","class":"OC\\Server","type":"->","args":[]},{"file":"/var/www/html/lib/base.php","line":1091,"function":"init","class":"OC","type":"::","args":[]},{"file":"/var/www/html/index.php","line":35,"args":["/var/www/html/lib/base.php"],"function":"require_once"}],"File":"/var/www/html/lib/private/DB/Connection.php","Line":72,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36 Edg/87.0.664.41","version":"19.0.1.1"}
{"reqId":"CMTHqbkJMgmdWdX9ebtI","level":3,"time":"2020-12-01T21:21:46+00:00","remoteAddr":"192.168.1.99","user":"--","app":"core","method":"GET","url":"/","message":{"Exception":"Doctrine\\DBAL\\DBALException","Message":"Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused","Code":0,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":1449,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":892,"function":"getWrappedConnection","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/Connection.php","line":202,"function":"executeQuery","class":"Doctrine\\DBAL\\Connection","type":"->","args":["SELECT * FROM `oc_appconfig`",[],[],null]},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php","line":206,"function":"executeQuery","class":"OC\\DB\\Connection","type":"->","args":["SELECT * FROM `oc_appconfig`",[],[]]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":217,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":345,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":110,"function":"loadConfigValues","class":"OC\\AppConfig","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppConfig.php","line":301,"function":"getApps","class":"OC\\AppConfig","type":"->","args":[]},{"file":"/var/www/html/lib/private/legacy/OC_App.php","line":949,"function":"getValues","class":"OC\\AppConfig","type":"->","args":[false,"installed_version"]},{"file":"/var/www/html/lib/private/TemplateLayout.php","line":185,"function":"getAppVersions","class":"OC_App","type":"::","args":[]},{"file":"/var/www/html/lib/private/legacy/OC_Template.php","line":183,"function":"__construct","class":"OC\\TemplateLayout","type":"->","args":["error",""]},{"file":"/var/www/html/lib/private/Template/Base.php","line":132,"function":"fetchPage","class":"OC_Template","type":"->","args":[]},{"file":"/var/www/html/lib/private/legacy/OC_Template.php","line":332,"function":"printPage","class":"OC\\Template\\Base","type":"->","args":[]},{"file":"/var/www/html/index.php","line":63,"function":"printExceptionErrorPage","class":"OC_Template","type":"::","args":[{"__class__":"Doctrine\\DBAL\\DBALException"},500]}],"File":"/var/www/html/lib/private/DB/Connection.php","Line":72,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36 Edg/87.0.664.41","version":"19.0.1.1"}

@Norrox Please don’t hijack this thread, because your problem is totally different to original one (“Could not find driver” != “Connection refused”). Please use the search function of this forum to find related answers. Database connection problems are addressed and answered on a regular base.

I thought it was the same error or related somehow, since i have the error 500 message aswell, guess the error codes is not that specific. Sorry if I stept on someone’s toes.

1 Like

So i’m confused, i wound up here searching for this same issue. However i run this php script and it works just fine. I run php - i and all the modules are enabled. Not only that, i have other php programs like phpmyadmin running flawlessly.

Is there any way to get a more descriptive error from nextcloud?

Nevermind, solved the problem. apparently running
chown -R www-data:www-data nextcloud
fixes everything, even though nginx typically does not need that.
if you’re running nginx, it’s still important to do the www-data step. leaving this here for anyone else who gets stuck like me.

2 Likes

I had the same issue after running sudo ncp-dist-upgrade after I upgraded to 1.36.2

For me the issue was the existance of multiple php versions on the system.
I had php5.6, php.7.0, php7.1, php7.2, php7.3 and php8.0 installed.

with whereis php I found all the different locations, which mentioned different versions.
I removed all php packages, except for php7.3.

After that I restarted apache2 and it worked.

3 Likes

Great tip! I had PHP 7.2, 7.3, and 7.4 packages installed, but 7.3 was the most complete (most packages installed), and it seemed like maybe I was missing something from PHP 7.4. I just apt remove php7.2* and apt remove php7.4 and now things look good! I recently upgraded to Debian bullseye (11) so I’m guessing that’s where my problem originated.

I’m beginning to think it might be easier to run Nextcloud on something a little more cutting-edge like Fedora or openSUSE…

2 Likes

Great, this worked for me as well. I had php8.0 and 8.1 installed and used ‘sudo apt remove 8.1*’ and then followed up with ‘sudo -u www-data:www-data php occ files:scan -v --all’ and wallah!

1 Like

I solved this issue in my case by de-commenting extension=pdo_mysql in my php.ini file (for me in /etc/php/php.ini)

1 Like