Internal server error - Failed to connect to the database

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

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:

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 31.0.4.1
  • Operating system and version (e.g., Ubuntu 24.04):
    • Ubuntu 22.04.5 LTS
  • Web server and version (e.g, Apache 2.4.25):
    • Apache 2.4.52
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • replace me
  • PHP version (e.g, 8.3):
    • 8.3
  • Is this the first time you’ve seen this error? (Yes / No):
    • yes
  • When did this problem seem to first start?
    • after update ubuntu server
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • replace me
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • no

Summary of the issue you are facing:

After update && upgrade of ubuntu server my nextcloud instance is no more accessible. Neither through internet connection nor locally. When trying to reach the login page by internet the connection is timing out. Trying to establish the connection locally an internal server error is thrown.
Apache2 log shows no errors.
occ is not working either. It throws an unhandled exception:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /var/www/html/nextcloud/lib/private/DB/Connection.php:237

Steps to replicate it (hint: details matter!):

  1. Try to access login page or
  2. try any occ command

Log entries

Nextcloud

Please provide the log entries from your Nextcloud log that are generated during the time of problem (via the Copy raw option from Administration settings->Logging screen or from your nextcloud.log located in your data directory). Feel free to use a pastebin/gist service if necessary.

{"reqId":"b6RbL9x1IYydeLcydMhP","level":3,"time":"2025-04-26T20:40:01+02:00","remoteAddr":"","user":false,"app":"cron","method":"","url":"--","message":"Failed to connect to the database: An exception occurred in the driver: could not find driver","userAgent":"--","version":"31.0.4.1","exception":{"Exception":"Doctrine\\DBAL\\Exception","Message":"Failed to connect to the database: An exception occurred in the driver: could not find driver","Code":0,"Trace":[{"file":"/var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php","line":458,"function":"connect","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php","line":416,"function":"getDatabasePlatformVersion","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php","line":323,"function":"detectDatabasePlatform","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/DB/Connection.php","line":903,"function":"getDatabasePlatform","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/DB/ConnectionAdapter.php","line":235,"function":"getDatabaseProvider","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php","line":96,"function":"getDatabaseProvider","class":"OC\\DB\\ConnectionAdapter","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/AppConfig.php","line":1226,"function":"expr","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/AppConfig.php","line":243,"function":"loadConfig","class":"OC\\AppConfig","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/AppConfig.php","line":1366,"function":"searchValues","class":"OC\\AppConfig","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/App/AppManager.php","line":136,"function":"getValues","class":"OC\\AppConfig","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/App/AppManager.php","line":157,"function":"getInstalledAppsValues","class":"OC\\App\\AppManager","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/legacy/OC_App.php","line":188,"function":"getInstalledApps","class":"OC\\App\\AppManager","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":48,"function":"getEnabledApps","class":"OC_App","type":"::"},{"file":"/var/www/html/nextcloud/lib/base.php","line":675,"function":"runInitialRegistration","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/html/nextcloud/lib/base.php","line":1156,"function":"init","class":"OC","type":"::"},{"file":"/var/www/html/nextcloud/cron.php","line":24,"args":["/var/www/html/nextcloud/lib/base.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/lib/private/DB/Connection.php","Line":237,"message":"Failed to connect to the database: An exception occurred in the driver: could not find driver","exception":{},"CustomMessage":"Failed to connect to the database: An exception occurred in the driver: could not find driver"}}

Web Browser

If the problem is related to the Web interface, open your browser inspector Console and Network tabs while refreshing (reloading) and reproducing the problem. Provide any relevant output/errors here that appear.

PASTE

Web server / Reverse Proxy

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

PASTE HERE

Configuration

Nextcloud

The output of occ config:list system or similar is best, but, if not possible, the contents of your config.php file from /path/to/nextcloud is fine (make sure to remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'sectret',
  'passwordsalt' => 'secret',
  'secret' => 'secret',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '127.0.0.1',
    'port' => 6379,
    'timeout' => 0.5,
    'dbindex' => 1,
  ),
  'trusted_domains' => 
  array (
    0 => 'secret',
    1 => 'secret.de/nextcloud',
    2 => '192.168.0.250',
  ),
  'trusted_proxies' => 
  array (
    0 => '192.168.0.250',
    1 => '127.0.0.1',
    2 => '::1',
    3 => '192.168.0.1',
    4 => 'secret',
    5 => 'secret',
    6 => 'secret',
  ),
  'enabledPreviewProviders' => 
  array (
    0 => 'OC\\Preview\\PNG',
    1 => 'OC\\Preview\\JPEG',
    2 => 'OC\\Preview\\GIF',
    3 => 'OC\\Preview\\BMP',
    4 => 'OC\\Preview\\XBitmap',
    5 => 'OC\\Preview\\Movie',
    6 => 'OC\\Preview\\PDF',
    7 => 'OC\\Preview\\MP3',
    8 => 'OC\\Preview\\TXT',
    9 => 'OC\\Preview\\MarkDown',
  ),
  'datadirectory' => '/media/Nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '31.0.4.1',
  'overwrite.cli.url' => 'secret',
  'overwritehost' => 'secret',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'secret',
  'dbpassword' => 'secret',
  'installed' => true,
  'maintenance' => true,
  'mail_from_address' => 'secret',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'secret',
  'mail_smtpauth' => 1,
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpname' => 'secret',
  'mail_smtppassword' => 'secret',
  'mail_smtpsecure' => 'tls',
  'mail_smtphost' => 'secret',
  'mail_smtpport' => '25',
  'theme' => '',
  'loglevel' => 2,
  'default_phone_region' => 'DE',
  'maintenance_window_start' => 1,
  'log_type' => 'file',
  'logtimezone' => 'Europe/Berlin',
  'logfile' => '/var/log/nextcloud.log',
  'syslog_tag' => 'Nextcloud',
);

Apps

The output of occ app:list (if possible).

Tips for increasing the likelihood of a response

  • Use the preformatted text formatting option in the editor for all log entries and configuration output.
  • If screenshots are useful, feel free to include them.
    • If possible, also include key error output in text form so it can be searched for.
  • Try to edit log output only minimally (if at all) so that it can be ran through analyzers / formatters by those trying to help you.

Your question has been asked here many many times.

Short words:
You did an OS upgrade and now you are missing php module for your db.

Search the forum or the web on how to install suitable php module.

2 Likes

Whilst it is heartwarming to know there is an answer to this issue it is not as easy to resolve as you make it sound.

I have been searching for the answer to this for over three weeks and have not come across it. Please may you supply greater detail to you answer.

Thank you in advance

You can fix your php with the → php-updater ← script

h.t.h.


Much and good luck,
ernolf

Thank you for the help.

Unfortunately, after running the script, I am still no further forward. The same error still exists. I will leave it for today as my patience is wearing thin and return to the issue tomorrow.

Again, thank you for your help.

After a lot of tinkering and the use of the php-updater script I ended up uninstalling all php modules that weren’t version 8.3.
To do that I used sudo apt list --installed | grep php to list all installed php-modules and then uninstalled every single module not being version 8.3 (by ‘sudo apt purge php8.1-apcu’ for example).
In the end I also had another problem with 6tunnel on my vps as the ipv6 prefix of my server had meanwhile changed without me noticing it.
But now my nextcloud instance seems to be fine again after two frustrating weeks.
I had also not found fitting answers in the forum or by googleing the internet before I wrote the question above.

Nevertheless thanks for pointing in the general direction of the solution.

Exactly as recommended in the php-updater script. :+1:

But that wasn’t necessary! The data is best displayed WITHIN the php-updater script. Aditionaly a list with the installed packages was written to a file named:

/tmp/ebtb/log/<10digit-unix-timestamp>-php-updater-_SYSINF_afterwards.txt

At the end of the script, the exact command for purging is provided. For example, if you want to remove all packages related to php8.1, the command would be:

sudo apt-get purge '*php8.1*'

exactly as shown here, with single quotes around the asterisk wildcards to protect them from globbing.

It’s that simple. Everything else is unnecessary.


Much and good luck,
ernolf

1 Like

Since you hijacked someone else’s post instead of filling out a support template form yourself, no one knows what your “error” is about.

Please explain your problem in detail instead of simply stating that “the same error” still exists. Otherwise no one here can help you that way.

And believe me, I would love to help you!


ernolf