How do I fix this error when running a cron job for Moodle 3.9?

2.4k Views Asked by At

I have a Moodle site running on localhost. Everything seems to be running fine, but I can't seem to run the cron job. I keep getting the error when I try to run sudo -u www-data /usr/bin/php /opt/lampp/htdocs/moodle/admin/cli/cron.php from the command line.

!!! <p>Error: Database connection failed</p>
<p>It is possible that the database is overloaded or otherwise not running properly.</p>
<p>The site administrator should also check that the database details have been correctly specified in config.php</p> !!!

Moodle is installed on a Lampp (/opt/lampp/htdocs/), and this is my configuration file. My moodle data is in /var/moodledata I've changed the user for the database, used a password, but nothing works.

$CFG->dbtype    = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'moodle';
$CFG->dbuser    = 'root';
$CFG->dbpass    = '';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbport' => '',
  'dbsocket' => '',
  'dbcollation' => 'utf8mb4_unicode_ci',
);

$CFG->wwwroot   = 'http://localhost/moodle';
$CFG->dataroot  = '/var/moodledata';
$CFG->admin     = 'admin';

$CFG->directorypermissions = 0777;
1

There are 1 best solutions below

0
On

You need unmark "Site administration/General/Security/Site security settings/Cron execution via command line only" option for run cron with url.