ULTRAMAX
ULTRAMAX

Reputation: 101

How To Disable Data Directory Check in Moodle 3.3+ Installation

Hello Dear Friends I have A Problem of Instaling Moodle 3.3+ Moodle can't create data directory "moodledata" outside of public_html...

As usual when installing moodle by default it creates data directory outside of the public_html.. I contacted to my host for that issue.. and they said for security reasons they wouldn't let me to create moodledata directory outside of public_html...

So i decided to change the data directory location (public_html/moodledata/), but the moodle installation says "Dataroot location is not secure"... Then i did chomd that directory "770" and I also put the .htaccess file with: order deny,allow deny from all

I got the same result: "Dataroot location is not secure"

Now I need to disable the moodle dataroot installation security check..

I did some changes but got error...

here is the code:

//first time here? find out suitable dataroot

if (is_null($CFG->dataroot)) { $CFG->dataroot = DIR.'/../moodledata';

$i = 0; //safety check - dirname might return some unexpected results
while(is_dataroot_insecure()) {
    $parrent = dirname($CFG->dataroot);
    $i++;
    if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
        $CFG->dataroot = ''; //can not find secure location for dataroot
        break;
    }
    $CFG->dataroot = dirname($parrent).DIRECTORY_SEPARATOR.'moodledata';
}
$config->dataroot = $CFG->dataroot;
$config->stage    = INSTALL_WELCOME;

}

How to disable it correctly? (of course I want to do it with my own risk, I'm)..

Thank you all In Advanced, With Best Wishes!

Upvotes: 1

Views: 1125

Answers (2)

wordpresrox
wordpresrox

Reputation: 618

This is not the best way of doing it but coding hack to just get rid of this error if you like try it..,

in moodle root go the install.php and if you are using 2.6 in line 341 or others versions search for is_dataroot_insecure() function and change it to false in the else if condition and try to install again,and that it..,

enter image description here

Upvotes: 0

davosmith
davosmith

Reputation: 6327

The easiest way to force the check to pass would be to open up lib/adminlib.php, find the function is_dataroot_insecure() and add the following at the start of the function:

function is_dataroot_insecure($fetchtest=false) {

    return false; // CORE MODIFICATION - disable checks

    ... the original function code appears here ...

That said, this is a very bad idea from a security perspective - it would potentially allow anyone on the internet to browse through the files in your Moodle site.

I would strongly recommend you find a better hosting provider, as this one does not sound suitable for hosting a Moodle site. If you have only a small number of users, then a free Moodle Cloud account might be a suitable solution. Otherwise, you could consider paying for hosting with a Moodle Partner.

Upvotes: 3

Related Questions