"Database connection failed" from running cron on local computer

"Database connection failed" from running cron on local computer

by Mike Smith -
Number of replies: 6
Dear Moodle Experts,

I installed Moodle 3.11 on my local computer and when I tried to run cron.php today, I got "Error: Database connection failed". What about be the issue? I restarted the server but the below error still exists.

Below is my Terminal when rununing php admin/cli/cron.php,


mike@mike-MacBook-Air moodle311 % php admin/cli/cron.php

PHP Deprecated:  Return type of navigation_node_collection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/navigationlib.php on line 1145


Deprecated: Return type of navigation_node_collection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/navigationlib.php on line 1145

PHP Deprecated:  Return type of navigation_node_collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/navigationlib.php on line 1134


Deprecated: Return type of navigation_node_collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/navigationlib.php on line 1134

PHP Deprecated:  Return type of moodle_recordset::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/moodle_recordset.php on line 61


Deprecated: Return type of moodle_recordset::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/moodle_recordset.php on line 61

PHP Deprecated:  Return type of context::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/accesslib.php on line 5173


Deprecated: Return type of context::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/accesslib.php on line 5173

PHP Deprecated:  Return type of cm_info::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/modinfolib.php on line 1427


Deprecated: Return type of cm_info::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/modinfolib.php on line 1427

PHP Deprecated:  Return type of section_info::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/modinfolib.php on line 3018


Deprecated: Return type of section_info::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/modinfolib.php on line 3018

PHP Deprecated:  Return type of mysqli_native_moodle_recordset::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/mysqli_native_moodle_recordset.php on line 65


Deprecated: Return type of mysqli_native_moodle_recordset::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/mysqli_native_moodle_recordset.php on line 65

PHP Deprecated:  Return type of mysqli_native_moodle_recordset::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/mysqli_native_moodle_recordset.php on line 78


Deprecated: Return type of mysqli_native_moodle_recordset::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/mysqli_native_moodle_recordset.php on line 78

PHP Deprecated:  Return type of mysqli_native_moodle_recordset::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/mysqli_native_moodle_recordset.php on line 69


Deprecated: Return type of mysqli_native_moodle_recordset::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/mysqli_native_moodle_recordset.php on line 69

PHP Deprecated:  Return type of mysqli_native_moodle_recordset::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/mysqli_native_moodle_recordset.php on line 82


Deprecated: Return type of mysqli_native_moodle_recordset::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Applications/MAMP/htdocs/moodle311/lib/dml/mysqli_native_moodle_recordset.php on line 82

PHP Deprecated:  Creation of dynamic property cache_config::$configlockmappings is deprecated in /Applications/MAMP/htdocs/moodle311/cache/classes/config.php on line 146


Deprecated: Creation of dynamic property cache_config::$configlockmappings is deprecated in /Applications/MAMP/htdocs/moodle311/cache/classes/config.php on line 146

PHP Deprecated:  substr(): Passing null to parameter #1 ($string) of type string is deprecated in /Applications/MAMP/htdocs/moodle311/lib/setuplib.php on line 663


Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /Applications/MAMP/htdocs/moodle311/lib/setuplib.php on line 663

PHP Deprecated:  substr(): Passing null to parameter #1 ($string) of type string is deprecated in /Applications/MAMP/htdocs/moodle311/lib/setuplib.php on line 663


Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /Applications/MAMP/htdocs/moodle311/lib/setuplib.php on line 663

PHP Deprecated:  substr(): Passing null to parameter #1 ($string) of type string is deprecated in /Applications/MAMP/htdocs/moodle311/lib/setuplib.php on line 668


Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /Applications/MAMP/htdocs/moodle311/lib/setuplib.php on line 668

!!! <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> !!!

mike@mike-MacBook-Air moodle311 % 


Average of ratings: -
In reply to Mike Smith

Re: "Database connection failed" from running cron on local computer

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Mike, is your Moodle working except for cron?
 
See Leon's post about PHP version, which could be your problem.
In reply to Rick Jerz

Re: "Database connection failed" from running cron on local computer

by Mike Smith -
Dear Rick,

Thank you for your reply. Yes, my Moodle is working and I have been using it for a week. When I installed Moodle I didn't set up cron. Now I need to set cron up because I am developing an emailing plugin that needs to send emails to students and this plugin is using mdl_event table to send the emails.

My PHP version is PHP 8.3.4, please see below,

mike@mike-MacBook-Air moodle311 % php -version
PHP 8.3.4 (cli) (built: Mar 12 2024 23:42:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.4, Copyright (c) Zend Technologies
with Zend OPcache v8.3.4, Copyright (c), by Zend Technologies
mike@mike-MacBook-Air moodle311 %
In reply to Mike Smith

Re: "Database connection failed" from running cron on local computer

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

What do you get for php --version? Is this PHP version compatible with Moodle 3.11, which requires PHP 7.4 or PHP 8.0?

In reply to Leon Stringer

Re: "Database connection failed" from running cron on local computer

by Mike Smith -
Dear Leon,

Thank you for your attention. My PHP version is PHP 8.3.4, please see below,

mike@mike-MacBook-Air moodle311 % php -version
PHP 8.3.4 (cli) (built: Mar 12 2024 23:42:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.4, Copyright (c) Zend Technologies
with Zend OPcache v8.3.4, Copyright (c), by Zend Technologies
mike@mike-MacBook-Air moodle311 %

Your document says Moodle 3.11 supports PHP 8.0.x but mine is PHP 8.3.4, in this case, do I need to install the latest version of PHP 8.0.x ?

Thanks!

Mike
In reply to Mike Smith

Re: "Database connection failed" from running cron on local computer

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

As Rick says you must use a PHP version which is compatible with your Moodle version.

If your web server is already running a suitable PHP version (check the PHP info page to find out the web server's version) then maybe you need to specify the path to a different php file when running cron.php. If you're using MAMP on your Mac then maybe this path is /Applications/MAMP/bin/php/phpX.Y.Z/bin/php where X.Y.Z is the version from PHP info, for example, 8.0.30 or 7.4.33.