Cron not run for days - php fatal db connection

Cron not working with PHP fatal error for DB connection
  1. Admin page stats that Cron hasn’t run for days.
  2. I check Cron on the server which is fine
  3. I run the Cron job and get errors on line 64 of the Connection.php.
  4. I searched for similar problems.
  5. I logged in with nextcloud credentials to the mysql server, all okay.
  6. Check logs.
  7. Stuck at what could be wrong.

Nextcloud version 15.0.6 & 15.0.7:
Operating system and version Ubuntu 16.04:
Apache2 2.4.18: I am running it through a reverse proxy which has same version.
PHP version 7.3.4):

The issue you are facing:
I have been running Nextcloud for sometime, approximately since the move from owncloud occurred, and in the last few days I saw on the admin page that cron hasn’t been run for 15 days. I checked my server and nothing obvious has been changed except maybe some security updates.
I ran
php -f /var/www/nextcloud/cron.php
and got

PHP Fatal error:  Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: could not find driver in /var/www/nextcloud/lib/private/DB/Connection.php:64
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/nextcloud/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configura in /var/www/nextcloud/lib/private/DB/Connection.php on line 64
PHP Fatal error:  Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: could not find driver in /var/www/nextcloud/lib/private/DB/Connection.php:64
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/nextcloud/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configura in /var/www/nextcloud/lib/private/DB/Connection.php on line 64

I can log into the mysql server from the nextcloud server using the nextcloud login and password. I did the update to 15.0.7 incase there was a bug and gave no errors which leads me to believe that nextcloud can log into the database.

Is this the first time you’ve seen this error? Yes:

Steps to replicate it:

  1. let Nextcloud use cron
    or
  2. run php -f /var/www/nextcloud/cron.php

The output of your Nextcloud log has nothing related to this, only the recent update and deleting images or music app related:

The output of your config.php file:

<?php
$CONFIG = array (
  'instanceid' => 'XXXXXX',
  'passwordsalt' => 'XXXXXX',
  'secret' => 'XXXXXX',
  'trusted_domains' => 
  array (
    0 => '192.168.1.12', #nextcloud server
    1 => 'XXXXXX',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'overwrite.cli.url' => 'https://XXXXXX',
  'htaccess.RewriteBase' => '/nextcloud',
  'dbtype' => 'mysql',
  'version' => '15.0.7.0',
  'dbname' => 'nextcloud',
  'dbhost' => '192.168.1.16:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'XXXXXX',
  'dbpassword' => 'XXXXXX',
  'installed' => true,
  'trusted_proxies' => 
  array (
    0 => '192.168.1.5', #proxy server
  ),
  'overwriteprotocol' => 'https',
  'maintenance' => false,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'filelocking.enabled' => 'true',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'theme' => '',
  'loglevel' => 2,
  'mail_from_address' => 'cloud',
  'mail_smtpmode' => 'smtp',
  'mail_domain' => 'XXXXXX',
  'mail_smtphost' => 'XXXXXX',
  'mail_smtpport' => 'XXXXXX',
  'mail_smtpauth' => 1,
  'mail_smtpname' => 'XXXXXX',
  'mail_smtppassword' => 'XXXXXX',
  'onlyoffice' => 
  array (
    'verify_peer_off' => true,
    'jwt_secret' => 'XXXXXX',
    'jwt_header' => 'XXXXXX',
  ),
  'updater.secret' => 'XXXXXX',
);

The output of your Apache error log in :

[Sat Apr 20 06:25:05.061637 2019] [mpm_prefork:notice] [pid 467] AH00163: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
[Sat Apr 20 06:25:05.061714 2019] [core:notice] [pid 467] AH00094: Command line: '/usr/sbin/apache2'
[Sat Apr 20 07:01:38.399351 2019] [autoindex:error] [pid 2296] [client 192.168.1.5:48992] AH01276: Cannot serve directory /var/www/nextcloud/: No matching DirectoryIndex (none) found, and server-generated directory index forbidden by Options directive
[Sat Apr 20 07:02:19.254706 2019] [authz_core:error] [pid 2294] [client 192.168.1.5:49206] AH01630: client denied by server configuration: /var/www/nextcloud/data/.ocdata
[Sat Apr 20 07:02:47.976034 2019] [authz_core:error] [pid 2595] [client 192.168.1.5:49252] AH01630: client denied by server configuration: /var/www/nextcloud/data/.ocdata
[Sat Apr 20 12:26:10.428502 2019] [mpm_prefork:notice] [pid 467] AH00169: caught SIGTERM, shutting down
[Sat Apr 20 12:26:32.636931 2019] [mpm_prefork:notice] [pid 476] AH00163: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
[Sat Apr 20 12:26:32.637119 2019] [core:notice] [pid 476] AH00094: Command line: '/usr/sbin/apache2'
[Sat Apr 20 12:34:10.737823 2019] [php7:error] [pid 482] [client 192.168.1.5:51166] PHP Fatal error:  Uncaught Doctrine\\DBAL\\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused in /var/www/nextcloud/lib/private/DB/Connection.php:64\nStack trace:\n#0 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\\DB\\Connection->connect()\n#1 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\\DBAL\\Connection->getDatabasePlatformVersion()\n#2 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\\DBAL\\Connection->detectDatabasePlatform()\n#3 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\\DBAL\\Connection->getDatabasePlatform()\n#4 /var/www/nextcloud/lib/private/DB/Connection.php(151): Doctrine\\DBAL\\Connection->setTransactionIsolation(2)\n#5 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\\DB\\Connection->__construct(Array, Object(Doctrine\\DBAL\\Driver\\PDOMySql\\Driver), Object(Doc in /var/www/nextcloud/lib/private/DB/Connection.php on line 64
[Sat Apr 20 12:34:10.739029 2019] [php7:error] [pid 482] [client 192.168.1.5:51166] PHP Fatal error:  Uncaught Doctrine\\DBAL\\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused in /var/www/nextcloud/lib/private/DB/Connection.php:64\nStack trace:\n#0 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\\DB\\Connection->connect()\n#1 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\\DBAL\\Connection->getDatabasePlatformVersion()\n#2 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\\DBAL\\Connection->detectDatabasePlatform()\n#3 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\\DBAL\\Connection->getDatabasePlatform()\n#4 /var/www/nextcloud/lib/private/DB/Connection.php(151): Doctrine\\DBAL\\Connection->setTransactionIsolation(2)\n#5 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\\DB\\Connection->__construct(Array, Object(Doctrine\\DBAL\\Driver\\PDOMySql\\Driver), Object(Doc in /var/www/nextcloud/lib/private/DB/Connection.php on line 64
[Sat Apr 20 12:47:03.935854 2019] [authz_core:error] [pid 942] [client 192.168.1.5:51490] AH01630: client denied by server configuration: /var/www/nextcloud/data/.ocdata
[Sat Apr 20 12:47:13.744760 2019] [authz_core:error] [pid 513] [client 192.168.1.5:51536] AH01630: client denied by server configuration: /var/www/nextcloud/data/.ocdata
[Sat Apr 20 12:53:42.156522 2019] [authz_core:error] [pid 1030] [client 192.168.1.5:51960] AH01630: client denied by server configuration: /var/www/nextcloud/data/.ocdata
[Sat Apr 20 12:53:48.482358 2019] [authz_core:error] [pid 945] [client 192.168.1.5:51986] AH01630: client denied by server configuration: /var/www/nextcloud/data/.ocdata
[Sat Apr 20 12:54:12.642622 2019] [authz_core:error] [pid 1039] [client 192.168.1.5:52070] AH01630: client denied by server configuration: /var/www/nextcloud/data/.ocdata
[Sat Apr 20 12:54:31.279909 2019] [authz_core:error] [pid 1031] [client 192.168.1.5:52096] AH01630: client denied by server configuration: /var/www/nextcloud/data/.ocdata

Looking at the above I don’t know what would be calling for the database through 192.168.1.5 ( which is the reverse proxy server) as it is already configured to be 192.168.1.16 (the database).

If you can point me in the right direction on how to resolve this I would be most grateful.

Thanks

Same issue here. Hopefully someone jumps in and helps us…

A bit weird but I was checking the php modules I had and some had gone missing?!?!?!
I went through the php modules required on the installation instructions on nextcloud documentation and typed php -m to list the ones on my machine, found the following had gone so re installed them then reboot.

  • php-gd
  • php-mbstring
  • php-mysql
  • php-xml

Though I had to do phpenmod mbstring to get it going again.
Seems to be working now. Hope this helps others.