[SOLVED] Error on cron.php execution

I made a fresh install of NextCloud 24.0.1 in a LXC container, on a Raspberry Pi 3B running LXD/LXC.

I decided to install MariaDB in an other LXC container. MariaDB is in version 15.1

mariadb --version
mariadb  Ver 15.1 Distrib 10.5.15-MariaDB, for debian-linux-gnueabihf (armv7l) using  EditLine wrapper

My NC instance is working well, but in the administrator configuration menu Base parameters, I have the message that someting went wrong with the last task execution. I can choose the Cron parameter, but it never stays activated.

I configure the www-data user crontab like that :

# sudo crontab -e -u www-data
*/5 * * * * php -f /var/www/nextcloud/cron.php --define apc.enable_cli=1

When I try t execute manually the cron.php from a root session, I have this errors :

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

I am confused because the connection to my database is ok, my NC instance is working weel.

You can find here an extract of my /var/www/nextcloud/config/config.php :

# cat /var/www/nextcloud/config/config.php 
<?php
$CONFIG = array (
  'instanceid' => 'xxxx',
  'passwordsalt' => 'xxxxx',
  'secret' => 'xxxxx',
  'trusted_domains' => 
  array (
    0 => 'nextcloud.xxxx.org',
    1 => '192.168.1.11',
  ),
  'datadirectory' => '/var/data_nextcloud',
  'dbtype' => 'mysql',
  'version' => '24.0.1.1',
  'overwrite.cli.url' => 'http://10.60.243.98/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => '10.60.243.175',
  'dbport' => '3306',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'oc_gannick',
  'dbpassword' => 'xxxxx',
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'trusted_proxies' => 
  array (
    0 => '10.60.243.1',
  ),
  'default_phone_region' => 'FR',
  'mail_from_address' => 'xxxx',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'xxxx.fr',
  'mail_smtphost' => 'smtp.xxxx.fr',
  'mail_smtpport' => '25',
);

Strangerly, I installed everything with PHP 8.0, but when I check PHP version, this is 8.1, when I try to switch to 8.0, I got a message saying that Module PHP 8.1 does not exist :

root@nextcloud:/var/www/nextcloud# sudo a2dismod php8.1
ERROR: Module php8.1 does not exist!
root@nextcloud:/var/www/nextcloud# sudo a2enmod php8.0
Considering dependency mpm_prefork for php8.0:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php8.0:
Module php8.0 already enabled
root@nextcloud:/var/www/nextcloud# php -v
PHP 8.1.7 (cli) (built: Jun 14 2022 10:25:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.7, Copyright (c), by Zend Technologies

So, my question is : do you know how to make the cron working ?

**Bonus question : **
In the admin panel, I have correcting every warning message, except one that I cannot : The PHPs modules "gmp" and/or "bcmatch" aren't active. If you are using authentication whithout password WebAuthn, this modules are required.

When I am looking for modules :

# php -m
[PHP Modules]
apcu
bcmath
calendar
Core
ctype
date
exif
FFI
fileinfo
filter
ftp
gettext
gmp
hash
iconv
imagick
json
libxml
openssl
pcntl
pcre
PDO
Phar
posix
readline
Reflection
session
shmop
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
Zend OPcache
zlib

[Zend Modules]
Zend OPcache

Maybe this is related to the strange response of my php -v ?

Thanks everyone by advance.

So, I found by myself a solution I will explain for every one.

Strangely, as I say, I have PHP 8.1 which is responding although I did not install it…

To force PHP 8.0 to be used instead of PHP 8.1 :

# update-alternatives --config php

Then, select the PHP 8.0. After that, it was not still good, I had to put the option –define apc.enable_cli = 1.

After that, I could launch by myself the command :

# sudo -u www-data php -f /var/www/nextcloud/cron.php --define apc.enable_cli=1

No error ! And in the admin panel, cron is well selected.

The question about the module’s warning that I cannot bypass have also been solved by the change of PHP version. The modules BCMATH and GMP was installed, but for PHP 8.1. After the switch to PHP 8.0, I had to installed them.

Now, no warning anymore !

Hope this could help someone…