$CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

$CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Adrian O'Sullivan -
Number of replies: 24

I have two separate domains running Moodle.

I have read countless posts on this topic, but none provides a solution for my problem.

Recently, I migrated my Moodle 2.4.11 site to a new server. The file structure looks absolutely fine on the new server; identical to the old one in fact. Yet, despite editing configure.php correctly, and setting all permissions correctly, when I try to open the site in my browser, all I get is the dreaded message:

$CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

Curiously, I have also installed a new Moodle 3.2 site on the same server, with its own separate database and seemingly flawless structure, yet I am getting the same error message for that too: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

Help!

Average of ratings: -
In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Ken Task -
Picture of Particularly helpful Moodlers

Have to assume that what you've said is 100% accurate for no other hints/clues/info is shared concerning operating system nor what that 'structure' looks like.   So the only thing I can suggest is check the config.php file.   At the very bottom of that file it says in comments:

// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
X

There shouldn't be extra carriage returns (hidden to you in any editor) after the last line.   When editing with a text editor the editor cursor cannot move downward from the X locaton above.  The 'X' in above example just shows where ... it should NOT be included in the config.php.

When you save the file it must be at least readable by owner/group of the web service user.  On a CentOS linux box that shows like (which may not the same on your server):

-rw-r----- 1 apache apache 1094 Feb  5 21:53 config.php

Since you've migrated one site, you had to edit the config.php file to set new paths, etc. so there's a chance there that above is the issue.   On the latest release of a 3 (3.0.2+) the same is true IF you hand edited the config.php file when installing.

If that doesn't fix it, then we need to hear/see more information related to operating system, remotely hosted or not,  and that 'file struture' of which you spoke.   In a previous posting you provided an entire example config.php file.   Really don't need an entire example config.php file but do need to get a peak on the values for $CFG->dataroot.   Because this might involve permissions/ownerships on the server, that's why the info on remotely hosted or not.

'spirit of sharing', Ken

In reply to Ken Task

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Ken... that's actually not true. What causes problems is white space beyond any closing ?> at the end of a PHP file. That is why it is no longer recommended to include the closing tag. Without it you can have as many blank lines as you like and it doesn't matter.

In reply to Howard Miller

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Ken Task -
Picture of Particularly helpful Moodlers

Ok, stand corrected.   Thanks!  However, if OP did follow directions he might have actually removed the closing php tag (had it been present) and thus resolved the problem without really knowing the technical reasons in the greater context of Moodle code. smile   But, I shall make a note and next time, try to respond in a more 'technically correct' manner.

Anyway ... +1 to your questions.  Let's hope the OP will investigate and post back.

In researching this, found the OP had tweeted successfull installation of a 2.6 via one of those installer scripts that you and I both 'love so much'. :|  And, it appears, if the op is hosting with same provider, Rick might need to stick around as Rick has been successful installing newer versions of Moodle on the providers systems (provided they are VPS's).

'spirit of sharing', Ken


In reply to Ken Task

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes - I do love those installer scripts. You just never know what fun and games they are going to come up with next big grin

In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

dataroot is referring to your moodledata folder.  As Ken mentioned for the config.php file, check ownership and permisssions and that it is in the location specified by your config.php file.

In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Might you be able to tell us exactly, step by step, you installed your "new" moodle?

Emma's suggestion is good.  When I install from scratch, I like to create my moodledata folder and then change its permissions to 777.  The owner and group of this folder is the same, and it is the same as what shows when I do a "whoami" command.  But years ago I had problems with this owner/group issue.  Ken would probably be able to guide you better about this.

Also, what "collation" are you using for your database?

Have you added a database user?  And is this the user that you are entering when moodle installs?

I recall getting the error message that you have gotten, and in the past, I had to solve this with knowing exactly what I needed to enter.  Like many computer systems, one little thing not being correct can cause problems.

In reply to Rick Jerz

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

As long as the server is secure and not shared with users you don't trust 0777 (everyone!) permissions are the easy way to set this up and the most likely to just work.

I'm unsure why you are asking about database settings. It's nothing to do with the database wink

In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

"despite editing configure.php correctly, and setting all permissions correctly"

...with respect, you didn't. If you had, it would be working.

It's config.php of course, but I expect that's a typo. Almost without fail it's a permissions issue that causes this. 

Other than that, you give us almost no information to help you. OS? Moodle version? Layout of files? Show us the ownership and permissions?

Did you check your web server error log?

In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Adrian O'Sullivan -

First, thank you all for the tremendous response to this topic. I will spend tomorrow (Sunday) digesting all that you have suggested and attempting to implement relevant suggestions. I 

It hasn't helped that my new hosts appear to be shut at weekends, so no tech support for server-side issues will be available until Monday. sad

I really don't think we have a permissions issue here. I have double-checked them all, and I'm satisfied that permissions are AOK.

Whilst I agree that config.php needs further investigation (which I shall do tomorrow), I also think there may be server-related issues at play (which cannot be examined until Monday). The fact that both Moodle domains (3.2 and 2.4.11) with separate databases are returning the same error message suggests that a common server glitch may be the cause of my distress. 

For instance, it is possible that the server may be set up to prevent access to database folders outside public_html. I know that this has been an issue for Moodlers in the past.

Also, this is a recently commissioned server, which may still be having teething troubles. I say this because I'm having FTP and email problems too, which may be attributable to new-server problems.

I hope to update the topic by Tuesday.

Thanks again.

Adrian


 

 

In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sorry... I'm having a pedantic day. You (I think) don't mean 'database' in this context, I think. You are still talking about $CFG->dataroot which are just files. As the database is something else entirely, I just wanted to be clear. 

You should probably try enabling Debugging (see section 7 of config-dist.php). This could just possibly be the dreaded 'open_basedir' setting in php.ini.  With debugging on you should get a proper error message about that though. See http://php.net/manual/en/ini.core.php#ini.open-basedir

In reply to Howard Miller

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Adrian O'Sullivan -

Sorry, I was having a senior's moment when I mentioned configure.php. It happens sometimes, and with increasing frequency as I approach my 75th.

By "database file" I meant the "moodledata" directory that resides in the home directory, referred to as "dataroot" in config.php.

So, I have uncommented debugging in section 7 of configure.php, but I haven't a clue where I am supposed to find the explicit error messages you speak of.

So far, when I attempt to open my front page, I'm getting the same simple "$CFG->dataroot is not configured properly" error message as before. And nothing else.


 

In reply to Howard Miller

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Adrian O'Sullivan -

Is this any help? Error messages regarding cron have been piling up in my email inbox, as follows:

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

Debug info: Access denied for user 'xxx_xxx'@'localhost' to database
'xxx_xxx'
Error code: dbconnectionfailed
Stack trace: * line 449 of /lib/dml/mysqli_native_moodle_database.php:
dml_connection_exception thrown
* line 344 of /lib/dmllib.php: call to mysqli_native_moodle_database->connect()
* line 615 of /lib/setup.php: call to setup_DB()
* line 828 of /config.php: call to require_once()
* line 33 of /admin/cli/cron.php: call to require()
In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Ok, so your error messages are both pointing to your config.php file.

You need to double check all the info in that file.  It is possible that due to being on a new server, you do not have the correct path to moodledata folder assigned.  Either that or the permissions and ownership are incorrect on moodledata folder.

Your email messages are telling you that the user that you have set for the database does not have access.  So, you need to change that in your config.php file.  I have heard of people actually deleting the config.php file (backup first) and then let the moodle installer let you put in the details for your moodledata folder and database user.  This might work in this case and help you ensure that your config.php file is setup correctly.

In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes - you have two errors now. As Emma points out, this means that your database credentials are wrong. You obviously need to fix this but it won't help the $CFG->dataroot problem. 

In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

I wonder if you might not have "mysqli" turned on in you php configuration.  You should be able to check for this by running the "info.php" command.  When I do this, I see the results below (along with all other types of information.)  I am not anywhere near an expert on these matters, but I do see one line you the message that you provided about "mysql".  Notice how my "mysqli" shows "enabled."

Attachment mysqli.jpg
In reply to Rick Jerz

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Again, this is the database issue (not the 'moodledata' issue). And, no, a missing driver wouldn't get this far. It has to make a basic connection in order to try authenticating. This is either an incorrect 'grant' at the MySQL end and/or the wrong details in config.php (or both).

In reply to Howard Miller

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Adrian O'Sullivan -

Well, Sunday has produced only one change in the situation. Concentrating on my 2.4.11 installation, which is a clone of that which was running happily on the old server (same domain), I now get the following HTML page in my web browser:

<title>Error</title>

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

</div></body></html>

I notice that this browser page is generated in Gill Sans font, which is clearly based on the modified .css files within my Moodle theme. So, something's working!

In other words, I'm now clearly getting beyond the $CFG error message, but I still cannot connect with the database.

My config.php is correct, and my permissions are correct. (db username and password correct; db name correct).

I tried moving the 'moodledata' folder to within public_html (with an .htaccess file in it), but that produces the same HTML message as above. So 'moodledata' is now back where it belongs.

Is it not most likely that the problem is with the server: perhaps some incompatibility with the versions of MySQL and/or PHP on the hosting server?

The versions are shown in cPanel as MySQL 10.0.23-MariaDB and PHP  5.6.17.

Do you see anything in the following server setup that might be causing problems with either Moodle 2.4.11 or Moodle 3.0.2?

Apache Version2.4.18
PHP Version5.6.17
MySQL Version10.0.23-MariaDB
Architecturex86_64
Operating Systemlinux
Shared IP Address91.247.228.143
Path to Sendmail/usr/sbin/sendmail
Path to Perl/usr/bin/perl
Perl Version5.16.3
Kernel Version3.14.58-4.el7.lowsecurity.art.x86_64
In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Ken Task -
Picture of Particularly helpful Moodlers

Info shared shows running MariaDB.

Check the config.php file for DB type and DB Library.

For MariaDB they should be:

$CFG->dbtype    = 'mariadb';
$CFG->dblibrary = 'native';

The DB server, DB user, and DB password for the DB user should also be checked.  The DB information one should be able to see in cPanel's button for DB.

Make sure that all variables in the config.php file have proper formatting ... values enclosed by 'ticks' and each line ends with ";".

The wwwroot should not end with a "/' as well as the path to your moodledata ... should not end with a "/".

No need to restart apache or any service.  As soon as those edits are in there the next browser that hit's the site should see something Moodle.    Edit the config.php file with a text editor so that doesn't get re-confused. ;)

BTW, issues with Moodle seldom have to do with the location of moodledata directory if it's in proper location to begin.  Best NOT to move it unless you know (exactly) what you are doing and why.

'spirit of sharing', Ken

In reply to Ken Task

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Adrian O'Sullivan -

OK, so I made the suggested change as follows:

$CFG->dbtype    = 'mariadb';

$CFG->dblibrary = 'native';

And this produces a new, different error page, as follows:

<p>Error: database driver problem detected</p>

<p>The site administrator should verify server configuration</p>

<p>Unknown driver native/mariadb</p>

What next?

In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Ken Task -
Picture of Particularly helpful Moodlers

Well, that's one step closer, huh?

Check to see if you have php extensions for MySQL installed.

MariaDB doesn't require a special php extension, it will use the one for MySQL.

Use your cPanel to check and acquire ... if that's how one does it on your shared system.

If you need help with that, you might have to contact your providers help desk/trouble ticket or check the providers FAQ's/client KnowledgeBase or whatever help they have for clients.

'spirit of sharing', Ken

In reply to Ken Task

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The OP posted yesterday...

Debug info: Access denied for user 'xxx_xxx'@'localhost' to database
'xxx_xxx'
Error code: dbconnectionfailed

...so it isn't the driver. You wouldn't get an error message like that if it was. Assuming we are all talking about the same thing, the same Moodle and nothing has changed. To be honest, I'm wondering if we're getting all the bits of the story here sad

In reply to Howard Miller

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Ken Task -
Picture of Particularly helpful Moodlers

Previously OP shared:

"The versions are shown in cPanel as MySQL 10.0.23-MariaDB and PHP  5.6.17"

So .... ????

'spirit of sharing', Ken



In reply to Ken Task

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Adrian O'Sullivan -

Problem solved by the sysadmin. It had nothing to do with Moodle but was a cPanel/SQL problem.

It seems that I had not added the user to the database in cPanel. You have to add the user to the database via the mysql panel in cPanel and give it all privileges. That will then allow the user to connect to the database.

So I'm now connected, and the website is running normally.

Thanks for all the advice. All's well that ends well!

Adrian


In reply to Adrian O'Sullivan

Re: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Adrian, one never know what kind of information will help.  Up above, this was one of my suggestions (i.e., add a user to the database.)  Well, now you know.

In my cPanel, there is an icon to add a mysql database.  Then, after creating a database, you can create and add a user, and finally assign this user to the database.  The is the "user" that gets entered into config.php.   I still go over to phpmyadmin to make sure collation is set for utf8_unicode.  Then I am finished with the database.

When I do my installs from scratch, I never dabble with the config.php file.  During the moodle install, there is a screen that asks for database information (including the user).  If you fill out everything correctly in this dialog box, you won't need to touch config.php.   However, the experience that you gained from all of this will help you be a better moodler.   Good luck.