Moodle Migration Error: Database connection failed

Keywords: Moodle - Google Cloud Platform - Technical issue - Other
bnsupport ID:
I have followed instructions from [here] ( and [here] (Migrating moodle from old bitnami stack to new file structure).
I have migrated all of the files required across and I’m trying to get the instance to work.
When I’m accessing the instance, I get;

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

I notice that the config.php of the old and new instance are slightly different.
The biggest thing I notice is the change from mysqli to mariadb and I feel that this may be the issue.

<?php  // Moodle configuration file


global $CFG;

$CFG = new stdClass();

$CFG->dbtype    = 'mariadb';

$CFG->dblibrary = 'native';

$CFG->dbhost    = '';

$CFG->dbname    = 'bitnami_moodle';

$CFG->dbuser    = 'bn_moodle';

$CFG->dbpass    = '41500c7038';

$CFG->prefix    = 'mdl_';

$CFG->dboptions = array (

  'dbpersist' => 0,

  'dbport' => 3306,

  'dbsocket' => '',

  'dbcollation' => 'utf8_general_ci',


if (empty($_SERVER['HTTP_HOST'])) {

  $_SERVER['HTTP_HOST'] = '';


if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {

  $CFG->wwwroot   = 'https://' . $_SERVER['HTTP_HOST'];

} else {

  $CFG->wwwroot   = 'http://' . $_SERVER['HTTP_HOST'];


$CFG->dataroot  = '/bitnami/moodledata';

$CFG->admin     = 'admin';

$CFG->directorypermissions = 02775;

require_once(__DIR__ . '/lib/setup.php');

// There is no php closing tag in this file,

// it is intentional because it prevents trailing whitespace problems!

Hi @adriancblood,

I see the next errors in the Apache logs.

[Mon Sep 07 07:16:10.333659 2020] [proxy_fcgi:error] [pid 2906:tid 140042903119616] [client] AH01071: Got error 'PHP message: PHP Warning:  require_once(/opt/bitnami/moodle/lib/setup.php): failed to open stream: No such file or directory in /opt/bitnami/moodle/config.php on line 37PHP message: PHP Fatal error:  require_once(): Failed opening required '/opt/bitnami/moodle/lib/setup.php' (include_path='.:/opt/bitnami/php/lib/php') in /opt/bitnami/moodle/config.php on line 37'
[Mon Sep 07 08:10:41.809082 2020] [proxy_fcgi:error] [pid 2906:tid 140042877941504] [client] AH01071: Got error 'PHP message: PHP Warning:  unlink(/bitnami/moodledata/cache/core_component.php): Permission denied in /opt/bitnami/moodle/lib/classes/component.php on line 312'

Can you try to run the next command?

sudo chown -R bitnami:daemon /opt/bitnami/moodle

Apart from that, I don’t know if there is anything else you need to change when migrating from MySQL to MariaDB. Can you check it in the official Moodle forums?

Hi gongomgra, Thanks for that. It didn’t fix the error.
I can see the setup.php is in /opt/bitnami/moodle/lib/setup.php
I’ve gone through the Moodle forums, but will sift through again.


Hi @adriancblood,

Thanks for letting us know. Did you have any chance to check if there is any new error message in the Apache logs after updating the filesystem permissions?

I restarted the server and then thought to check if Apache or any of the other services are running, and they’re not.
Going to the apache log.

i/moodle/lib/classes/component.php on line 312'
[Mon Sep 07 23:08:38.980658 2020] [ssl:warn] [pid 742:tid 139919508265856] AH01909: server certificate does NOT include an ID which matches the server name```
These are the 2 that seem to repeat.

Hi @adriancblood,

Can you run the bnsupport tool again so we can check the updated logs and configuration?

Hi gongomgra,

ef584877-1de1-fe73-0eea-b6d5454d1bc3 refers.
Thanks for your help, I appreciate it.

Hi @adriancblood,

Although you updated the permissions I keep seeing the same error message about this in the logs.

[Thu Sep 10 00:48:48.271334 2020] [proxy_fcgi:error] [pid 1395:tid 139918659970816] [client] AH01071: Got error 'PHP message: PHP Warning:  unlink(/bitnami/moodledata/cache/core_component.php): Permission denied in /opt/bitnami/moodle/lib/classes/component.php on line 312'

Can you try setting daemon as the owner of the entire /opt/bitnami/moodle directory? daemon is the user running the Apache service

sudo chown -R daemon:daemon /opt/bitnami/moodle

If the above doesn’t work, please ask for help in the Moodle forums on how to debug this issue explaining we checked the ownership of Moodle’s files is set to the user running Apache

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.