Fedora 40 Error: Failed to connect to the database: An exception occurred in the driver

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 29.0.5): 28.0.10
Operating system and version (eg, Ubuntu 24.04): Fedora 40
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.62
PHP version (eg, 8.3): 8.1.30

The issue you are facing:
Just upgraded to Fedora 40. It broke Nextcloud. Updating Nextcloud showed me this error:

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/html/nextcloud/lib/private/DB/Connection.php:150

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

Steps to replicate it:

  1. Upgrade to Fedora 40
  2. Run sudo -u apache php --define apc.enable_cli=1 updater.phar

The output of your Nextcloud log in Admin > Logging:

PASTE HERE

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

<?php
$CONFIG = array (
  'instanceid' => 'xxxxx',
  'passwordsalt' => 'xxxxxx',
  'secret' => 'xxxxx,
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => 'xxxxxxxxxxx
  ),
  'datadirectory' => '/xxx/xxxxxx/data',
  'dbtype' => 'mysql',
  'version' => '28.0.4.1',
  'overwrite.cli.url' => 'http://localhost/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'xxxxx',
  'dbpassword' => 'xxxxxx',
  'installed' => true,
  'maintenance' => true,
  'theme' => '',
  'loglevel' => 2,
  'data-fingerprint' => 'xxxxx',
  'filesystem_check_changes' => 0,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'enable_previews' => true,
  'preview_max_x' => 4096,
  'preview_max_y' => 4096,
  'preview_max_filesize_image' => 50,
  'preview_max_memory' => 1024,
);

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

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[Sun Sep 29 21:08:00.306974 2024] [lbmethod_heartbeat:notice] [pid 1142:tid 1142] AH02282: No slotmem from mod_heartmonitor
[Sun Sep 29 21:08:00.309034 2024] [systemd:notice] [pid 1142:tid 1142] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Sun Sep 29 21:08:00.316193 2024] [mpm_event:notice] [pid 1142:tid 1142] AH00489: Apache/2.4.62 (Fedora Linux) OpenSSL/3.2.2 configured -- resuming normal operations
[Sun Sep 29 21:08:00.316222 2024] [core:notice] [pid 1142:tid 1142] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

Same error from updater.phar

It means Nextcloud can’t connect to your database server. It appears you use MySQL so check the state of your MySQL server.

Refs: General troubleshooting — Nextcloud latest Administration Manual latest documentation