Internal server error occ SQLSTATE exception

Nextcloud version (eg, 20.0.5): can't find a way to check
Operating system and version (eg, Ubuntu 20.04): Debian 10
Apache or nginx version (eg, Apache 2.4.25): 2.4.38
PHP version (eg, 7.4): 7.3.31

The issue you are facing:

Hello,

I set up Nextcloud yesterday by the help of a Linode “one-click” app, and all has been working quite well so far. Today while I was moving some files using the Linux client Nextcloud suddenly went down, and gives the message:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

I have rebooted several times and tried to troubleshoot myself, but I am, admittedly, not an expert in this area and I can’t seem to nail down what has happened and how to fix it.

Interestingly (perhaps) in my steps to solve this I found that running sudo -u www-data php occ yields the following:

An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory in /var/www/nextcloud/lib/private/DB/Connection.php:87
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1519): OC\DB\Connection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1041): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /var/www/nextcloud/lib/private/DB/Connection.php(237): Doctrine\DBAL\Connection->executeQuery('SELECT * FROM `...', Array, Array, NULL)
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery('SELECT * FROM `...', Array, Array)
#4 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(287): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/nextcloud/lib/private/AppConfig.php(361): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/nextcloud/lib/private/AppConfig.php(126): OC\AppConfig->loadConfigValues()
#7 /var/www/nextcloud/lib/private/AppConfig.php(317): OC\AppConfig->getApps()
#8 /var/www/nextcloud/lib/private/legacy/OC_App.php(972): OC\AppConfig->getValues(false, 'installed_versi...')
#9 /var/www/nextcloud/lib/private/Server.php(692): OC_App::getAppVersions()
#10 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(160): OC\Server->OC\{closure}(Object(OC\Server))
#11 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#12 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(127): Pimple\Container->offsetGet('OC\\Memcache\\Fac...')
#13 /var/www/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query('OC\\Memcache\\Fac...', false)
#14 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(56): OC\ServerContainer->query('OC\\Memcache\\Fac...')
#15 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(182): OC\AppFramework\Utility\SimpleContainer->get('OC\\Memcache\\Fac...')
#16 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(160): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#17 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(114): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#18 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(127): Pimple\Container->offsetGet('OCP\\ICacheFacto...')
#19 /var/www/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query('OCP\\ICacheFacto...', false)
#20 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(56): OC\ServerContainer->query('OCP\\ICacheFacto...')
#21 /var/www/nextcloud/lib/private/Server.php(1079): OC\AppFramework\Utility\SimpleContainer->get('OCP\\ICacheFacto...')
#22 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(160): OC\Server->OC\{closure}(Object(OC\Server))
#23 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#24 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(127): Pimple\Container->offsetGet('OCP\\Lock\\ILocki...')
#25 /var/www/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query('OCP\\Lock\\ILocki...', false)
#26 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(56): OC\ServerContainer->query('OCP\\Lock\\ILocki...')
#27 /var/www/nextcloud/lib/private/Server.php(2040): OC\AppFramework\Utility\SimpleContainer->get('OCP\\Lock\\ILocki...')
#28 /var/www/nextcloud/lib/private/Files/View.php(118): OC\Server->getLockingProvider()
#29 /var/www/nextcloud/lib/private/Server.php(439): OC\Files\View->__construct()
#30 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(160): OC\Server->OC\{closure}(Object(OC\Server))
#31 /var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#32 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(127): Pimple\Container->offsetGet('OC\\Files\\Node\\H...')
#33 /var/www/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query('OC\\Files\\Node\\H...', false)
#34 /var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(56): OC\ServerContainer->query('OC\\Files\\Node\\H...')
#35 /var/www/nextcloud/lib/private/Server.php(1403): OC\AppFramework\Utility\SimpleContainer->get('OC\\Files\\Node\\H...')
#36 /var/www/nextcloud/lib/base.php(594): OC\Server->boot()
#37 /var/www/nextcloud/lib/base.php(1087): OC::init()
#38 /var/www/nextcloud/console.php(48): require_once('/var/www/nextcl...')
#39 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')

Any and all help will be greatly appreciated!

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

The output of your Nextcloud log in Admin > Logging:
No access.

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

<?php
$CONFIG = array (
  'passwordsalt' => '***',
  'secret' => '***',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '***',
    2 => '***',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '23.0.3.2',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => '***',
  'dbhost' => '***',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '***',
  'dbpassword' => '***',
  'installed' => true,
  'instanceid' => 'ocilrwwhleex',
  'has_rebuilt_cache' => true,
);

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

[Sun Mar 27 20:06:35.777612 2022] [core:notice] [pid 1848] AH00094: Command line: '/usr/sbin/apache2'
[Sun Mar 27 20:06:47.876045 2022] [mpm_prefork:notice] [pid 1848] AH00169: caught SIGTERM, shutting down
[Sun Mar 27 20:06:47.948756 2022] [mpm_prefork:notice] [pid 1889] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Sun Mar 27 20:06:47.948789 2022] [core:notice] [pid 1889] AH00094: Command line: '/usr/sbin/apache2'
[Sun Mar 27 20:06:56.821971 2022] [mpm_prefork:notice] [pid 1889] AH00169: caught SIGTERM, shutting down
[Sun Mar 27 20:07:53.718110 2022] [mpm_prefork:notice] [pid 767] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Sun Mar 27 20:07:53.719296 2022] [core:notice] [pid 767] AH00094: Command line: '/usr/sbin/apache2'
[Sun Mar 27 20:09:21.062490 2022] [mpm_prefork:notice] [pid 767] AH00169: caught SIGTERM, shutting down
[Sun Mar 27 20:09:21.134670 2022] [mpm_prefork:notice] [pid 900] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Sun Mar 27 20:09:21.134707 2022] [core:notice] [pid 900] AH00094: Command line: '/usr/sbin/apache2'

To check your version of nextcloud:

  • Option 1, if you still have GUI access:

/index.php/settings/admin/overview will give you the NC version.

  • Option 2 if you have shh access:

/var/www/… …/netcloud/sudo -u www-data php occ status

  - version: 23.0.3.2
  - versionstring: 23.0.3

As you are using linode, they have to provide you support. Their virtual server are intricate with different service and if one temporary fail, you might be impacted.

I do not currently have GUI access, but ssh is working fine. Running sudo -u www-data php occ status results in the above mentioned exception “Failed to connect to the database”.

Hoping this is useful for someone: I got the same error and exception messages today (on local server running NC on Rocky Linux) and also couldn’t run occ. Then I noticed that my /etc/hosts file somehow didn’t list the correct IP address of my local Nextcloud server.

Editing /etc/hosts and restarting the server fixed the whole problem for me.