Fatal error during Moodle upgrade

Fatal error during Moodle upgrade

by Marcus Ng -
Number of replies: 9

We are using CentOS 7.4 and PHP 7.2 and are upgrading Moodle from 3.6.1 to 3.8.9

The upgrade process takes more than 8 hours but still cannot finish. It prompts the below error message:

Notice: Trying to get property 'forced_plugin_settings' of non-object in /var/www/html/moodle/lib/moodlelib.php on line 1477

Warning: array_key_exists() expects parameter 2 to be array, null given in /var/www/html/moodle/lib/moodlelib.php on line 1477

Notice: Trying to get property 'dirroot' of non-object in /var/www/html/moodle/cache/classes/factory.php on line 476

Warning: require_once(/cache/classes/dummystore.php): failed to open stream: No such file or directory in /var/www/html/moodle/cache/classes/factory.php on line 476

Fatal error: require_once(): Failed opening required '/cache/classes/dummystore.php' (include_path='/var/www/html/moodle/lib/pear:.:/var/www/html/moodle/php/lib/php') in /var/www/html/moodle/cache/classes/factory.php on line 476

Fatal error: Uncaught Error: Call to a member function is_transaction_started() on null in /var/www/html/moodle/lib/classes/shutdown_manager.php:137 Stack trace: #0 [internal function]: core_shutdown_manager::shutdown_handler() #1 {main} thrown in  in /var/www/html/moodle/lib/classes/shutdown_manager.php on line 137

Please advise how to fix this problem. Thanks a lot!

Average of ratings: -
In reply to Marcus Ng

Re: Fatal error during Moodle upgrade

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

Can you tell us more about the steps you are using to upgrading Moodle? The first fatal error appears to follow from:

Notice: Trying to get property 'dirroot' of non-object in /var/www/html/moodle/cache/classes/factory.php on line 476

This suggests that $CFG has not been initialised (non-object). How does your config.php start? It should say:

<?php  // Moodle configuration file

unset($CFG);
global $CFG;
$CFG = new stdClass();

The $CFG = new stdClass() line above makes $CFG an object, and $CFG is global – shared by all Moodle's PHP files. So if it's a non-object at some point then something has gone wrong.

In reply to Leon Stringer

Re: Fatal error during Moodle upgrade

by Marcus Ng -

I mainly followed the below website to perform the upgrade.
https://docs.moodle.org/38/en/Upgrading
Instead of using linux command "cp -pr", I uploaded the plugin codes with WinSCP.
Afterwards, I copied the original config.php back to /var/www/html/moodle.
I used the below security permission:
chown -R root /path/to/moodle 
chmod -R 0755 /path/to/moodle
And also, change the permission of executable files to 0644. Set ACL for user: daemon to have rwx

The config.php is something like the below:
unset($CFG); // Ignore this line
global $CFG; // This is necessary here for PHPUnit execution
$CFG = new stdClass();
$CFG->dbtype = 'mysqli'; // 'pgsql', 'mariadb', 'mysqli', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native'; // 'native' only at the moment
$CFG->dbhost = 'localhost'; // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname = 'moodledb'; // database name, eg moodle
$CFG->dbuser = 'xxxxx'; // your database username
$CFG->dbpass = 'yyyyy'; // your database password
$CFG->prefix = 'mdl_'; // prefix to use for all table names
$CFG->dboptions = array(
    'dbpersist' => false,       
    'dbsocket'  => false,     
    'dbport'    => '',       
    'dbhandlesoptions' => false,               
    'dbcollation' => 'utf8mb4_unicode_ci',                              
     );
$CFG->wwwroot = 'https://moodle.xxxx.edu';
$CFG->dataroot = '/var/www/html/moodledata';
The original config.php of our Moodle before upgrade does not include the statement of "CFG->dirroot". However, it has been working fine from time to time.
I wonder if I should add the below statement before performing the Moodle upgrade. I noticed that config-dist.php does not include this statement.
$CFG->dirroot = '/var/www/html/moodle';
Please advise. Thank you very much.

In reply to Marcus Ng

Re: Fatal error during Moodle upgrade

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

$CFG->dirroot is set automatically so you don't need to add this to config.php. The last lines of config.php should be:


require_once(__DIR__ . '/lib/setup.php');
 
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems! 

The above call to lib/setup.php then sets $CFG->dirroot:

$CFG->dirroot = dirname(__DIR__);

Regarding the upgrade steps: are you using the command line or browser? I've upgraded sites which with databases larger than 100 GB and they took much less than eight hours. For an upgrade like this you should use the command line. If you are, can you share the output before the error so we can see how far this gets?

Also: can you tell us how big the Moodle database is?

Average of ratings: Useful (1)
In reply to Leon Stringer

Re: Fatal error during Moodle upgrade

by Marcus Ng -
The statement require_once(__DIR__ . '/lib/setup.php'); is correct. I haven't changed anything.
Forgot to mention that it is just a dummy UAT site. I am using browser to perform the upgrade. Our database is only about 1GB. It looks abnormal that it takes more than 8 hours while the upgrade is still not yet finished.
In reply to Marcus Ng

Re: Fatal error during Moodle upgrade

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

If you're using the browser then almost certainly a timeout is being exceeded causing this problem.

I would advise using the command line to upgrade the site. On CentOS the command (which should be run as root) is probably:

sudo -u apache php /var/www/html/moodle/admin/cli/upgrade.php

I'd expect it to take no more than a few minutes.

Average of ratings: Useful (2)
In reply to Marcus Ng

Re: Fatal error during Moodle upgrade

by Ken Task -
Picture of Particularly helpful Moodlers

Pardon intrusion ...

What does 'dbhandlesoptions' => false do?

Have searched config-dist.php in all versions of 2.x and 3.x and see no such setting.

There is only a tracker ... and that was for 3.2.

https://tracker.moodle.org/browse/MDL-56464

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: Fatal error during Moodle upgrade

by Marcus Ng -
The config-dist.php of our Moodle ver. 3.8.9 includes this statement 'dbhandlesoptions'=>false .I haven't changed anything.
In reply to Ken Task

Re: Fatal error during Moodle upgrade

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

Ken: Re 'dbhandlesoptions': This looks like a PostgreSQL-specific option where some database options are stored by the database server. The external database logstore also makes use of this functionality:

Database handles options (logstore_database | dbhandlesoptions)

Possible bug: searching admin settings doesn't show this option (on 3.9 at least).