Cronjob cannot be executed - Failed to connect to the database

Nextcloud version: 24.0.1
Operating system and version: Ubuntu 20.04
Apache or nginx version: Apache/2.4.41
PHP version: 8.0

The issue you are facing:
I installed an apcu cache for my Nextcloud about three hours ago. Something seems to have gone wrong, because since then the cron job no longer works. I could not find any error messages in any logs - only in the admin overview I am informed that the CronJob is not executed. I also tried to run this manually, then the following error comes up:

root@96185-81859:~# sudo -u www-data php -f /var/www/cloud.*********.de/cron.php --define apc.enable_cli=1
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /var/www/cloud.*********.de/lib/private/DB/Connection.php:139
Stack trace:
#0 /var/www/cloud.*********.de/3rdparty/doctrine/dbal/src/Connection.php(1519): OC\DB\Connection->connect()
#1 /var/www/cloud.*********.de/3rdparty/doctrine/dbal/src/Connection.php(1041): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /var/www/cloud.*********.de/lib/private/DB/Connection.php(261): Doctrine\DBAL\Connection->executeQuery()
#3 /var/www/cloud.*********.de/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery()
#4 /var/www/cloud.*********.de/lib/private/DB/QueryBuilder/QueryBuilder.php(281): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/cloud.*********.de/lib/private/AppConfig.php(411): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/cloud.*********.de/lib/private/AppConfig.php(176): OC\AppConfig->loadConfigValues()
#7 /var/www/cloud.*********.de/lib/private/AppConfig.php(367): OC\AppConfig->getApps()
#8 /var/www/cloud.*********.de/lib/private/legacy/OC_App.php(983): OC\AppConfig->getValues()
#9 /var/www/cloud.*********.de/lib/private/Server.php(713): OC_App::getAppVersions()
#10 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\Server->OC\{closure}()
#11 /var/www/cloud.*********.de/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#12 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet()
#13 /var/www/cloud.*********.de/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#14 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#15 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(184): OC\AppFramework\Utility\SimpleContainer->get()
#16 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#17 /var/www/cloud.*********.de/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#18 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet()
#19 /var/www/cloud.*********.de/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#20 /var/www/cloud.*********de/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#21 /var/www/cloud.*********.de/lib/private/Server.php(1105): OC\AppFramework\Utility\SimpleContainer->get()
#22 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\Server->OC\{closure}()
#23 /var/www/cloud.*********de/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#24 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet()
#25 /var/www/cloud.*********.de/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#26 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#27 /var/www/cloud.*********.de/lib/private/Server.php(2082): OC\AppFramework\Utility\SimpleContainer->get()
#28 /var/www/cloud.*********.de/lib/private/Files/View.php(122): OC\Server->getLockingProvider()
#29 /var/www/cloud.*********.de/lib/private/Server.php(454): OC\Files\View->__construct()
#30 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\Server->OC\{closure}()
#31 /var/www/cloud.*********.de/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#32 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet()
#33 /var/www/cloud.*********.de/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#34 /var/www/cloud.*********.de/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#35 /var/www/cloud.*********.de/lib/private/Server.php(1445): OC\AppFramework\Utility\SimpleContainer->get()
#36 /var/www/cloud.*********.de/lib/base.php(602): OC\Server->boot()
#37 /var/www/cloud.*********.de/lib/base.php(1104): OC::init()
#38 /var/www/cloud.*********.de/cron.php(43): require_once('...')
#39 {main}

I had the problem before a few times that something didn’t fit with the connection to the database, I could solve the errors though by using chmod. Today this did not work anymore. Also strange is that the cloud is otherwise running fine - only the cron job is broken.

I hope someone has an idea about this.

edit: I just tried to make changes via OCC, but again the error message comes up. Means: I can’t use occ either.

You should always read the whole message and not only a part of it. As you can see the database driver couldn’t be found, most likely because you haven’t correctly configured the PHP CLI, which uses a separate configuration than the PHP WEB component.

Thank you, that is indeed a clue. I had a look in the loaded plugins of PHP, there I could not find a plugin with the name CLI, but it is installed… Anyway, I can not install it, then comes the message that it is already there.
Is there any way to check if there is an error with the plugin? And yes, I already looked in /var/logs, I didn’t find anything useful there.

“CLI” stands for “Command Line Interface” and is not a name of a specific module. If you call “php”, “php8” or “php8-cli” on the command line this CLI is executed. It has a similar configuration as the php web interface and this is what you need to check. Most likely the MySQL driver isn’t correctly loaded. Please use the search function of the forum to find related postings:

https://help.nextcloud.com/search?q=Failed%20to%20connect%20to%20the%20database

Mhhh… So I’ve now searched through all the top entries and haven’t come across a single one on CLI or with the same error message as mine. For me your info is a dead end right now unfortunately, sorry. I also wouldn’t know where to find the configuration of CLI, I have no idea about it and haven’t found anything helpful on the internet either :confused:

and haven’t found anything helpful on the internet either

In this case you should improve your search capabilities :wink:

Use the following command to get an idea which command line options are supported:

# php -h

Use the following command to get the list of configuration files displayed and to find out where they are stored:

# php -i | grep "\.ini"

Use the following command to show a list of modules, loaded by the php cli:

# php -i | grep "^/etc/php"

1 Like

Thanks for your help, I let another employee of my hoster let look over it in parallel. He found the problem:
A long time ago I installed two PHP versions: 8.0 and 8.1. The cloud itself runs on 8.0 and there is also everything installed that the cloud needs. If I now call cron.php via cron or via SSH, it use 8.1, this can of course no longer work, because not all required PHP modules are installed.

But thanks in any case for your effort!

1 Like