Occ stopped working: octrine\DBAL\DBALException

I have been looking for the solution to this problem for many days. Unfortunately, I couldn’t find anything useful. Any help would be really appreciated as I am in a semi panic mode: my nextcloud instance does not work and I cannot bring it up.

Nextcloud version: 16.0.4
Operating system and version: Synology DSM
Apache or nginx version: Apache 2.4.39
PHP version: 7.2

I have been updating my Nextcloud (from 16.0.4 to 16.0.5) as I have been always doing: using cli.

First I did

sudo -u http php72 updater.phar

and everything went absolutely fine. Then I started upgrading with

sudo -u http php72 ./occ upgrade

and this is where the strangest things happened. I got a huge list of errors. They started as

An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory in /volume1/web/nexctcloud/lib/private/DB/Connection.php:64
Stack trace:
#0 /volume1/web/nexctcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(448): OC\DB\Connection->connect()
#1 /volume1/web/nexctcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(410): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /volume1/web/nexctcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(354): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /volume1/web/nexctcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(710): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /volume1/web/nexctcloud/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)

It looks like occ cannot connect to the database. But why and how to fix it? As I said, I always did exactly the same steps to upgrade and never had such problems before. I don’t know where even to begin looking for a solution as I couldn’t find anything useful on the web.

The output of your config.php file in /path/to/nextcloud:

<?php
$CONFIG = array (
  'instanceid' => '***',
  'passwordsalt' => '***',
  'secret' => '***',
  'trusted_domains' => 
  array (
    0 => '***.org',
  ),
  'datadirectory' => '/volume1/nc_data',
  'overwrite.cli.url' => 'https://192.168.1.10/nextcloud',
  'dbtype' => 'mysql',
  'version' => '16.0.4.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'oc_***',
  'dbpassword' => '***',
  'logtimezone' => 'UTC',
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'mail_smtpmode' => 'smtp',
  'maintenance' => true,
  'theme' => '',
  'loglevel' => 2,
  'updater.release.channel' => 'stable',
  'mail_from_address' => '***',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_domain' => '***',
  'mail_smtpsecure' => 'ssl',
);

Nextcloud relies on PHP and therefore you have to make sure that the php database driver is installed, both for the php web access and the php cli access. Make sure that the database itself is running and that you’ve installed the right driver.

Thank you a lot j-ed. I know very little about PHP and how it works. This makes your answer a bit cryptic for me. If you or anyone else could elucidate on this a bit more, I would be grateful. In particular, how do I check if the database is running and which driver has to be installed?

Also, since the upgrade always worked and I get this error message for the first time, I assume that the database or the driver might have gotten corrupted in the process of upgrading. Is this correct?

I realized that another useful piece of information is that occ gives the same error always, whichever parameters I use.

Afaik, you can install multiple differrent php versions in parallel on a Synology NAS. Each of them need to have its database modules installed to work properly. Due to the fact that Synology handles many things differently than other OSes, I couldn’t tell you how you can check things on it. Nevertheless several descriptions exist on the Internet describing how Nextcloud can be installed on such a device. Maybe this will lead you in the right direction:

https://www.google.com/search?client=firefox-b-d&q=nextcloud+on+synology

OK, can I ask a simpler question then, if you don’t mind?

I am using MariaDB 5. If my interpretation of your reply is correct, I need these PHP modules related to mysql installed: pdo_mysql, mysqli, mysqlnd. Is one of them a “database driver” that you are referring to?

More generally, these are the php modules installed on my system:

> php72 -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
imap
intl
json
ldap
libxml
mailparse
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
ssh2
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

Yes, I checked a few of them and my installation seams to be exactly as they recommend it to be. Moreover, I have been running Nextcloud for approximately 3 years now. So the initial installation must have been OK. Only this last minor update broke the installation.

From my point of view it is not Nextcloud which is causing the problem but your php or database setup. Have you checked if your database is running?

If I understand correctly, it is running.

> mysqladmin -u root -p status
Enter password:
Uptime: 921879  Threads: 1  Questions: 92839  Slow queries: 0  Opens: 4745  Flush tables: 2  Open tables: 4  Queries per second avg: 0.100

I also tried this thing, which I found on the net. I am not entirely sure if it useful, but in my understanding it shows that PHP can connect to the database without problems.

  1. I created a file /volume1/web/nextcloud/dbtest.php
 <?php
$servername = "localhost";
$username = "root";
$password = "***";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?> 
  1. Then I accessed this file on “https://IP.address/nextcloud/dbtest.php

  2. The result is

Connected successfully

After a lot of wasted time and hair pulling I found the solution. What needed to be done was a change from ‘dbhost’ => ‘localhost’ to ‘dbhost’ => ‘127.0.0.1’ in the nextcloud/config/config.php file.

So it seams that the problem was with nextcloud after all. I am really puzzled why I am the only one encountering this problem. But I’m happy my headache is over.

Thanks j-ed for your contribution.

1 Like