Failed to connect to database after upgrade to Ubuntu 22.04.1 LTS

Nextcloud version (eg, 20.0.5): 24.0.5.122.04.1 LTS
Operating system and version (eg, Ubuntu 20.04): Ubuntu
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.52
PHP version (eg, 7.4): Zend OPcache v8.1.2

The issue you are facing:
After updating Linux Ubuntu to 22.04.1 LTS,
Nextcloud is not starting. I get an Error in the Apache log:

PHP Fatal error:  Uncaught 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:139

However i can remotely connect to the database with same credentials like before the upgrade

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

Steps to replicate it:

  1. Start Ubuntu
  2. Check Apace log

The output of your Nextcloud log in Admin > Logging:

No Nextcloud log yet
<?php

$CONFIG = array (

  'auth.bruteforce.protection.enabled' => true,

  'instanceid' => 'oc6ebywp5leh',

  'passwordsalt' => 'dLnSmrEJ3T1iDiXh+c9MxKejzt7veh',

  'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',

  'trusted_domains' => 

  array (

    0 => 'localhost',

    1 => 'w392cloud.homeip.net',

    2 => '212.51.158.53',

  ),

  'datadirectory' => '/var/www/html/nextcloud/data',

  'dbtype' => 'mysql',

  'version' => '24.0.5.1',

  'overwrite.cli.url' => 'http://localhost/nextcloud',

  'dbname' => 'nextcloud',

  'dbhost' => 'localhost',

  'dbport' => '',

  'dbtableprefix' => 'oc_',

  'dbuser' => 'thomas',

  'dbpassword' => 'XXXXXXXXXXX',

  'installed' => true,

  'memcache.distributed' => '\\OC\\Memcache\\APCu',

  'memcache.local' => '\\OC\\Memcache\\APCu',

  'opcache.interned_strings_buffer' => '16',

  'enable_previews' => true,

  'enabledPreviewProviders' => 

  array (

    0 => 'OC\\Preview\\PNG',

    1 => 'OC\\Preview\\JPEG',

    2 => 'OC\\Preview\\GIF',

    3 => 'OC\\Preview\\BMP',

    4 => 'OC\\Preview\\HEIC',

    5 => 'OC\\Preview\\XBitmap',

    6 => 'OC\\Preview\\MP3',

    7 => 'OC\\Preview\\MP4',

    8 => 'OC\\Preview\\TXT',

    9 => 'OC\\Preview\\MarkDown',

    10 => 'OC\\Preview\\PDF',

  ),

  'preview_max_x' => NULL,

  'preview_max_y' => NULL,

  'preview_max_filesize_image' => 80,

  'preview_max_memory' => 256,

  'maintenance' => false,

  'theme' => '',

  'log_type' => 'file',

  'logfile' => '/var/log/nextcloud.log',

  'logfilemode' => 416,

  'loglevel' => 1,

  'logdateformat' => 'F d, Y H:i:s',

  'mysql.utf8mb4' => true,

  'updater.release.channel' => 'stable',

  'default_phone_region' => 'ISO 3166-2:CH',

  'mail_smtpmode' => 'smtp',

  'mail_sendmailmode' => 'smtp',

  'mail_from_address' => 'w392cloud',

  'mail_domain' => '3sweb.net',

  'mail_smtphost' => '3sweb.net',

  'mail_smtpport' => '587',

  'mail_smtpauth' => 1,

  'mail_smtpname' => ' w392cloud@3sweb.net',

  'mail_smtppassword' => 'XXXXXXXX',

  'mail_smtpsecure' => 'tls',

  'mail_smtpstreamoptions' => 

  array (

    'ssl' => 

    array (

      'security_level' => 2,

    ),

  ),

  'mail_smtpauthtype' => 'LOGIN',

);

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

[Wed Sep 14 01:05:36.198982 2022] [php7:error] [pid 1024945] [client 89.216.52.197:32174] 
PHP Fatal error:  Uncaught 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:139
Stack trace:
#0 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1519): OC\\DB\\Connection->connect()
#1 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1041): Doctrine\\DBAL\\Connection->getWrappedConnection()
#2 /var/www/html/nextcloud/lib/private/DB/Connection.php(261): Doctrine\\DBAL\\Connection->executeQuery('SELECT * FROM `...', Array, Array, NULL)
#3 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\\DB\\Connection->executeQuery('SELECT * FROM `...', Array, Array)
#4 /var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(281): Doctrine\\DBAL\\Query\\QueryBuilder->execute()
#5 /var/www/html/nextcloud/lib/private/AppConfig.php(411): OC\\DB\\QueryBuilder\\QueryBuilder->execute()
#6 /var/www/html/nextcloud/lib/private/AppConfig in /var/www/html/nextcloud/lib/private/DB/Connection.php on line 139

have you tried searching the forum for your problem?

you might come up with e.g. this one Upgrade Nextcloud instance from Ubuntu 20.04.4 LTS to 22.04.1 LTS

or many many others.

don’t forget to mention the fitting solution and maybe link any helpful hint here as well

I found the problem: php 8.1 was installed but not enabled foe apache2

Thanks for help.

1 Like

I have the same problem after updating Ubuntund to version 22. But what does “installed but not enabled foe apache2” mean?

Please search the web about enabling php for apache2. This is well known and documented at multiple ubuntu related websites.

Thanks for the clarification. This will certainly be of great help to Nextcloud users to do some research on the internet.

Hello @Teth ,

I wrote my comment to help you.
Setting up apache and php is basic webserver config and the base to run nextcloud.

Cheers.

I hope you’re having fun. Just a pity that you don’t take into account that Nextcloud provides virtual instance images on Ubuntu and your sarcastic remark about “basic configuration” is not relevant to this preconfigured Nextcloud server option.

Hello, your previous posts have been short and without any information about your environment. If you file a new support topic you have to fill in a template to give us volunteers enough information to help you. Please add such information and follow my friendly link to find the steps on how to enable php8.1 on your apache webserver.

No sarcastic greetings :wave:.

1 Like

On Ubuntu one can have multiple versions of apache installed. These can be enabled or disabled. The Ubuntu upgrade installed the new apache and php version but failed to enable the new version. I had to manually enable the new version using sudo a2enmod php8.0

1 Like