FATAL error:$CFG->dataroot is not writable, admin has to fix directory permissions!

Posted on

The error written in the title of the article which is ‘Fatal error:$CFG->dataroot is not writable, admin has to fix directory permissions !’ is an error triggered when the process of Moodle installation is being executed or it is being carried out. The error specifically popped-out in the form of white blank page with an error message written on it as specified in the title of the article. Below is the error in the form of an image shown as follows :

The error triggered above happens to have a relation or a connection with another error generated in the process of installing Moodle. Read this link of an article titled ‘Fatal error:$CFG->dataroot is not configured properly, directory does not exist or is not accessible!’.  The root or the cause of the problem is still the same but the difference is on the existence of the folder and the permission to write or to use the folder.  The error is clearly explained that the dataroot defined in the configuration file of Moodle named config.php cannot be written by Moodle which is executed via Apache Webserver.

So, the main issue is trying to fix or to solve the permission problem relies on moodledata folder. Check the Moodle configuration file located in the root folder of Moodle source installation named config.php. Normally it is located in ‘/var/www/html/moodle’ but it depends on the configuration and the envinroment.

$CFG->dataroot = '/home/example/moodledata';

The above is the default configuration entry for moodledata directory location which is normally exist in the Moodle source installation default named as ‘config-dist.php’. But in order to check the error, first of all, check whether the directory intended for has already exist. Below is the information regarding on the function of dataroot which is explained in ‘config-dist.php’ file :

// Now you need a place where Moodle can save uploaded files.  This
// directory should be readable AND WRITEABLE by the web server user
// (usually 'nobody' or 'apache'), but it should not be accessible
// directly via the web.
// - On hosting systems you might need to make sure that your "group" has
//   no permissions at all, but that "others" have full permissions.
// - On Windows systems you might specify something like 'c:\moodledata'

In the case of the folder for an example it has already created in the location ‘/var/www/html/moodle/moodledata’, the entry need to be defined in the file named config.php as shown below :

$CFG->dataroot = '/var/www/html/moodle/moodledata';

And after that, the permission of the folder need to be checked by executing the following command one of the way to do it :

root@hostname:/var/www# ls -alZ | grep moodledata
drwxrwxrwx  8 www-data www-data unconfined_u:object_r:httpd_sys_content_t:s0 4096 Jun 11 13:42 moodledata

The option -Z is an additional parameter added to print the SELinux security context. As it can be seen, to be able to solve the permission on accessing dataroot, below is several things need to be checked :

1. The owner of the folder. Make sure that the owner is the user or the group responsible for executing Apache Webserver.

2. The permission of the folder. Make sure that it is modified as 0777 to give access for writing. But if the SELinux is activated, it doesn’t need to set the permission as 0777.

3. For an environment where SELinux is activated, the most important thing is for SELinux is applied in the right away. In other means, the security context applied for those folders and files need to be written must be adjusted. It must have the security context label of ‘httpd_sys_rw_content_t’. If the security context hasn’t shown the label appropriate for Apache Webserver can able and can write the folder, just execute the following command :

root@hostname:/var/www/html# chcon -Rv -t httpd_sys_rw_content_t moodledata/

4 thoughts on “FATAL error:$CFG->dataroot is not writable, admin has to fix directory permissions!

    1. Apparently, you have to check your Moodle source code installation. The example above : $CFG->dataroot = ‘/var/www/html/moodle/moodledata’;, it is because the Moodle source code installation is in /var/www/html/moodle. If it exist in C:\xampp\htdocs\moodle, then the value will be $CFG->dataroot = ‘C:\xampp\htdocs\moodle’;. So, please carefully check for the path or the folder location of the Moodle source code installation.

Leave a Reply