Fatal error:$CFG->dataroot is not configured properly, directory does not exist or is not accessible!

Posted on

The error specified in the title of this article is displayed clearly in the progress of installing Moodle. Briefly explained, Moodle itself is an Open-source learning platform and it can be retrieved from its official website in this link. Upon setting up moodle in the local PC or laptop, the installation process halted and displayed a blank white page with the error printed on it. The error is written as specified in the title which is : “Fatal error:$CFG->dataroot is not configured properly, directory does not exist or is not accessible!”. Below is the image presented the error :

Fatal error:$CFG->dataroot is not configured properly, directory does not exist or is not accessible!
Fatal error:$CFG->dataroot is not configured properly, directory does not exist or is not accessible!

The above error is generated in the process of executing a Moodle placed in a directory located for executing web-based script via Apache Webserver. The location of the moodle is in /var/www/html/moodle. For more detail to describe the process, below is the steps written:

1. Download Moodle source installation form its official website located in here, or directly download the latest on in this link.

2. After finishing on downloading the Moodle source installation, extract it using any means or utilities available. In this context, it is done by executing the following command :

unzip moodle-latest-32.zip

The above execution command is extracting moodle opensource learning platform to local PC or laptop.

3. Do not forget to move the extracted files of Moodle installation source to the folder configured as default directory to be executed via webpage using Apache Webserver to server the access request page.  Below is the command to copy those files :

cp -rv * moodle/  /var/www/html

Depends on the account used, it must have a permission on /var/www/html in order to copy and write the moodle source installation. It can be done by using ‘root’ account and later on it can be modified into a folder which the permission suffice enough to be executed by Apache Webserver. The execution of copying moodle source installation using ‘root’ account :

root@hostname:~# cp -rv /home/user/moodle /var/www/html/

This is how we execute on giving the right permission to moodle source installation so that Apache Webserver can execute it and start running the installation process :

root@hostname:~# chown -Rv www-data.www-data /var/www/html/moodle/

4. After copying all the installation source of Moodle into the targeted location, just execute it in the web browser using the following URL :

http://localhost/moodle

* The above term, the URL as http://localhost practically can be anything depends on the condition and the environment of the main URL used to access local address provided by Apache Webserver. Normally it can be accessed using ‘http://localhost’.

The error happened most likely because the installation process is carried out manually by copying config-dist.php in the root folder of Moodle source installation since the folder doesn’t allow Apache Webserver to write a config.php inside it. Below is the process of copying config-dist.php into config.php :

root@hostname:/var/www/html/moodle# cp config-dist.php config.php
  1. Soon after, the process of installation will be continued by editing the config.php file where the error triggered an image displayed contains the  error specified in the title of the article is because of the following line of configuration:
$CFG->dataroot  = '/home/example/moodledata';

The above configuration script line is quite important since it is needed by Moodle. And this part is the main cause of the error generated. As shown in the explanation, the moodledata directory is intended for the following :

//======================================================================
// 3. DATA FILES LOCATION
//======================================================================
// 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.

So, to be able to solve the error triggered as shown in the title of this article, the following step is taken :

1. Make sure the location of $CFG->dataroot exist. It seems there is no problem if it is located outside the /var/www/html/moodle. For an example, the name of the folder is ‘moodledata’. To execute it further, just create the folder by executing the following command :

root@hostname:/var/www/html/moodle# mkdir moodledata

2. Not only the existance of the folder but also it can be accessed and written by Apache Webserver. To handle this problem in an environment where SELinux is activated, just modify the SELinux content security of the folder intended for that folder.

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

Don’t forget to set the owner of the folder to user and group dedicated for Apache Webserver  so that the folder itself can be executed by  Apache. Since the location of ‘moodledata’ directory is placed in ‘/var/www/html/moodle/moodledata’, don’t forget to edit the script file to be adjusted by simply changing the following entry :

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

If there isn’t any problemm further, moodle can already be accessed.

One thought on “Fatal error:$CFG->dataroot is not configured properly, directory does not exist or is not accessible!

Leave a Reply