dataroot is not writable, admin has to fix directory permissions

dataroot is not writable, admin has to fix directory permissions

by Andrew Bergman -
Number of replies: 29

Hello,

I'm in the process of installing moodle on CentOS 5.5 server, apache 2.2.3,  PHP 5.2.10, and backed by MSSQL 2008. Single instance of moodle running on the server.

I've created my dataroot as /usr/moodle_data/data and have the following in my config.php file:

[code]dataroot = '/usr/moodle_data/data[/code]

When attempting to load the admin page I get the follwoing error:

[quote]Fatal error: $CFG->dataroot is not writable, admin has to fix directory permissions! Exiting.[/quote]

This should indicate that the apache user (in my case "apache") does not have write access to /usr/moodle_data/data, but I get the error even if I chmod the directory 777.

Any help or suggestions appreciated.

Cheers.

Average of ratings: -
In reply to Andrew Bergman

Re: dataroot is not writable, admin has to fix directory permissions

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Make sure the parent directories of data/ are accessible to the apache user. They will need - at least - the 'x' permission for 'everybody' or it won't be able to see the data directory regardless of its permissions.
In reply to Howard Miller

Re: dataroot is not writable, admin has to fix directory permissions

by Andrew Bergman -

SElinux was the cause of my issues, would not let the apache user write outside of /var/www/html.

In reply to Andrew Bergman

Re: dataroot is not writable, admin has to fix directory permissions

by Khyam Shahzad -

Look into the .htaccess file inside the moodledata directory. This has resolved the issue at my end smile

In reply to Khyam Shahzad

Re: dataroot is not writable, admin has to fix directory permissions

by Abhishek Das -

what did you do in .htaccess file to fix the issue ? I'm new to moodle. I'm using IIS for development.

In reply to Abhishek Das

Re: dataroot is not writable, admin has to fix directory permissions

by Usman Asar -
Picture of Plugin developers Picture of Testers

Abi, for IIS, use this Tutorial HERE.

In reply to Andrew Bergman

Re: dataroot is not writable, admin has to fix directory permissions

by Francisco Cortes -

I recently dealt with this incident while I was moving an existent install and I wanted to share how I got it to work


source: digital ocean centos 6.5 32bit

target: server: centos-6.6 64 bit-v20141218 - in google cloud


the target server was giving me the dataroot is not writable, admin has to fix directory permissions error.

so here are my ownership, permissions and also locations for the folders among other details


document root form moodle install: /var/www/html/moodlefolder/

drwxr-xr-x.  3 apache apache 4096 Jan  7 01:21 html

apache is the owner of the html folder and also everything within it.


dataroot location : /var/www/data/

drwxr-xr-x. 11 apache apache 4096 Jan  7 01:23 data

apache is the owner of the data folder.


the database was dumped from the source server and later restore onto the target server (no issues during the restore)

and the db user was created for the database with all privideleges for that database.


In the config I changed

1. the moodle install location: >$CFG->wwwroot   = 'http://[new ip on gcloud instance]/moodlefolder'

2. set the data root: $CFG->dataroot  = '/var/www/data';

3. the dbname, dbuser. dbpass with the same info used when creating, importing and setting the user privideleges for the db user.


reload ...and then the error went away.


my reflexion:

I think that apache being the owner of the content with the documen root and the data folder and of course the appropiate permissions was key to get it resolved, setting up the 777 or 0770 was giving the same error until I completed all the steps above

If I should tied up my permissions as per the moodle experts any recommendations are welcome.



In reply to Francisco Cortes

Re: dataroot is not writable, admin has to fix directory permissions

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 short answer is that the web server user (apache in this case) needs to have write access to the 'moodledata' folder (/var/www/data) in your case. It needs to have the correct owner and/or permissions. If the permissions are 0777 then ownership is (should be!) irrelevant. 

I've said it before... if you are going to use Unix/Linux then half-an-hour spent learning how file permissions and ownership work is time very well spent wink

Average of ratings: Useful (1)
In reply to Howard Miller

Re: dataroot is not writable, admin has to fix directory permissions

by Francisco Cortes -

I agree with you 100 percent : understanding ownership and permissions are key to maintain linux/unix systems and whatever depends on them (ex. a moodle site on centos)

Thanks for summarizing my answer.

In reply to Francisco Cortes

Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by samarpita bansod -

we are not getting the solution on this problem.

 

Attachment File.png
In reply to samarpita bansod

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

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

You are!  You *need* to understand how permissions work on your chosen OS. There is no shortcut for this. If you don't have a basic understanding you will have constant frustration. 

In reply to Howard Miller

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Mauno Korpelainen -

Howard,

I have a feeling that Samarpita Bansod has not read (m)any docs about installing moodle so please be patient - that was his/her first post to these forums wink

That screenshot is not from Linux/Apache environment - it's from a local PC or server running IIS where www root is in C:\inetpub\wwwroot and moodledata could be for example in C:\inetpub\moodledata but not in C:\inetpub\wwwroot\moodledata

Permissions on IIS (Windows) can be problematic sometimes but if it is just a test PC giving full permissions for "correct user(s)" to  moodledata folder either with resource manager & mouse right click & security tab or IIS manager (if it's a server) might work - or might not. For example if the PC/server has PHP & FastCGI running on IIS7+ you may need to check or set the default anonymous www user of FastCGI module (for example IUSR) first ...

Google helps of course - or pages like https://docs.moodle.org/28/en/Internet_Information_Services big grin

In reply to Mauno Korpelainen

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

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

I hope I'm not being impatient... however, I have found that without a basic understanding of file ownership and permissions (regardless of the OS) even simple server administration is really difficult. There's huge numbers of tutorials on the web so there isn't much of an excuse. I'd much rather say "you will help yourself a lot if you understand this stuff" than just give out some commands to type in.

Give a man a fish, blah blah blah wink

In reply to Mauno Korpelainen

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by samarpita bansod -
yes i am installing moodle on my local pc having windows8 OS.and i have check what you say and my problem is solve so thanks
In reply to samarpita bansod

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
I thought we started with CentOS. When did it turn to this rubbish?
wink
In reply to samarpita bansod

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

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

Use the following terminal commands.

chown -R apache:apache moodledata (or name and location of your moodle data folder)

chmod -R 755 moodledata

apache:apache is the username:group for the apache user.  For some reason, I think the group might be different in CentOS but I don't have a current load to double check.  You might need to double check what group that user belongs to and then adjust the command.

There are several pages on LInux installations in the documents.  While they might not specifically mention CentOS, the other distribution pages have a lot of relevant info.  We should probably try and put a page up for CentOS as a lot of people are using that right now and there are a couple of quirks to it.

In reply to Emma Richardson

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Colin Rice -

Hi,

Just found this thread and it looks like the same problem I'm having and I'm tearing my hair out trying to fix it. Here's the background:

I'm installing Moodle 3.0.3+ on a CentOS 7 image. 

My dataroot is at /opt/moodledata and has permission 02777, owned by apache;apache. (my config.php states "$CFG->directorypermissions = 02777;" also)

My wwwroot is at /var/www/html/moodle.

I can get to the raw apache server at http://<myhost>/ fine

However, when I try and go to my moodle site at http://<myhost>/moodle I get the following:

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

I've read through the thread (and others) and can't see what the problem is. My permissions all look ok as I see it. I've also tried:

chcon -R -t httpd_sys_content_t /opt/moodledata

to see if SELinux is causing the problem.

I have no errors in my httpd logs other than a HTTP 503.

Nothing resolves the issue. Any ideas out there?

Thanks

Colin

In reply to Colin Rice

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

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

What are the permissions and ownership on your moodle folder?  Are all the permissions fixed recursively.  I have never seen a 02777 permission before - mine are all three numbers.  What does the 02 refer to I wonder?


In reply to Emma Richardson

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Colin Rice -

Thanks Emma.

My moodle (wwwroot) permissions are:

drwxr-xr-x. 45 root root 4096 Mar 31 15:09 moodle

(I've tried with apache:apache but made no difference, even after a httpd recycle).

My moodledata (dataroot) permissions are:

drwxrwsrwx. 9 apache apache 4096 Mar 31 14:31 moodledata

And both of the above are recursive to the sub-dirs.

The 02 I got from the Moodle install options (when running the install.php earlier it came up as a prompt), and apparently its the setuid or setgid bit. However, its academic as I've also tried just 755 or 777, and none of these fixed the problem.

Really at a stop here as I can't continue with the install sad

For any SElinux experts out there, I ran an ls -Z on the moodledata dir and got the following:

drwxrwsrwx. apache apache unconfined_u:object_r:usr_t:s0   moodledata

With these settings I see no errors in the /var/log/audit/audit.log, but if I add the security context httpd_sys_content_t 

to the moodledata dir as I saw suggested in the forums, then I get AVC denied errors in the log.

Cheers

Colin

UPDATE******

I tried dialing down SELinux to permissive and that resolved the dataroot issue, so I know its not just permissions and more to do with SELinux. At least now I can carry on with my Moodle install and look at SELinux later smile.


In reply to Colin Rice

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Colin Rice -

Thanks Ken.

I already tried earlier moving moodledata to /var/www but had no effect. 

See my updated posted above about SELinux though.

However I was thinking actually of just putting moodledata under /var/www in future anyway (as I'd seen this mentioned in other forums), so thanks for the advicesmile.


Cheers

Colin 

In reply to Colin Rice

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Ken Task -
Picture of Particularly helpful Moodlers

Yep, saw that.   Congrats on figuring out SELinux issue.

Would still recommend moving moodledata ... but that would require you to reset SELinux on the moved moodledata directory.    Might consider this ... put SELinux in 'permissive' mode ... you will see complaints by SELinux in logs then, and actually 'fix' them via the SELinux way.   Once you see no more complaints, set SELinux back to 'enforcing' and one shouldn't have to fool with that again ... for a looooooooooong time.

And, you can feel confident that your moodle is as secure as humanly possible - as long as you keep up with updates to the OS and to Moodle code.

My 2 'sense' of course!   Sometimes putting something off for later (the todo) somehow gets buried/forgotten and never again returns to the 'radar screen'/todo list.

Uhhhh ... we're still under: "Re: Data directory cannot be created by installer(c:/inetpub/"

Windows 10 might actually be moving closer to Linux (recent announcements with what to expect in their next release but your Linux issue is now buried under 'installer (C:\inetpub\).   Hmmmm ... just noticed the directory designators are in-correct for Windows platform ... oh, well.

'spirit of sharing', Ken

In reply to Colin Rice

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Ken Task -
Picture of Particularly helpful Moodlers

Apache already configured to use /var/www/ as it's area.   If you look in /var/www/ you'll probably see cgi-bin, icons, and maybe other directories (usage).

So my suggestion would be to move moodledata from /opt/moodledata to /var/www/

As root via command line:

mv /opt/moodledata /var/www/

cd /var/www/

chown apache:apache moodledata -R

chmod ug+rw moodledata -R

chmod o+r moodledata -R

Change config.php file for new location.   Shouldn't have to restart any services, just access via URL.

BTW, it's a good idea to always start a new thread even if you think your problem looks similar ... the subject of this thread is about Windows ... not CentOS 7 Linux. ;)

'spirit of sharing', Ken

In reply to Ken Task

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Gopal Sharma -
Picture of Plugin developers Picture of Testers

I simply given the permission in my Linux system to,

locate to you moodle installed directory in terminal, For eg. say /var/www/html/moodle

then type the following command to give the permission 


sudo find . -type d -exec chmod 777 {} \;


Though the giving 777 permission  to everyone is not advisable.

This solved my problem .

In reply to Gopal Sharma

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Atson Nakayama -
I am also experiencing the same issue with a moodle install on Ubuntu 15.04 with kernel 3.19.0-15-generic

I've tried chmod 777 on var/www/html/moodle and the fix above and they both don't work. I'm still getting the error "Fatal error: $CFG->dataroot is not writable, admin has to fix directory permissions! Exiting."

when trying to connect with http://localhost/moodle

Thanks for your help

I simply given the permission in my Linux system to,

locate to you moodle installed directory in terminal, For eg. say /var/www/html/moodle

then type the following command to give the permission 


sudo find . -type d -exec chmod 777 {} \;


Though the giving 777 permission  to everyone is not advisable.

This solved my problem .



In reply to Atson Nakayama

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

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

Check ownership and permissions are applied recursively to both moodle and moodledata folders.  

In reply to Emma Richardson

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by akihiro hashimoto -
Hi

This is similar to my problem.

My base is CentOS-7

I solved this problem as followings

1)  temporary solution   

   #  getenforce
   Enforcing
   #  setenforce

   # getenforce
   Permissive
   #  systemctl restart httpd.service

We found the two methods to solve this problem permanently as followings.
2-1)  method : disable selinux
  /etc/selinux/config
   SELINUX=disabled

2-2) other method

  #chcon -R -t httpd... Look  Moodle creating site data directory page


Akihiro HASHIMOTO Niigata college of nurisng

Average of ratings: Useful (1)
In reply to akihiro hashimoto

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Maharage Chande -

Dear Akihiro HASHIMOTO,

Thank you for the information very helpful. It was indeed a context type mismatch. I disabled SElinux, it worked, and then I enabled it, my expectation was that after enabling it I will get the same error, and I was prepared to get the error and fix it through changing the /var/www/html/moodle directory and its contents to the right context as required by SElinux theory. But after enabling it continue working and no error and the context was matching.

So, the source of the problem was the context. SElinux theory will help.


Cheers

Maharage 

In reply to Emma Richardson

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by 06S01at14163 itservice -

Today I ran into the same error.

After a while i got the idea.

On any linux box such as Red Hat, Cent OS, fedora and Co there is a pretty good likelihood that SELinux is enabled and enforced.

First of all you should check the directory and file permissions. Being at least accessible and readable to the web server - most often apache. Dirs and files should be owned by apache:apache.

The SELinux  is quite consequent. I therefore  ran into this issue after relabelling the system.

In case that after permission setting the web server still does complain about

„$CFG->dataroot not writable“ 

look at the SELinux labels of the dirs and files in $CFG->dataroot.

They are displayed with the CLI

ls -lZ /full_path_of_dataroot 

All labels should be

apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0  4096  1. Dez 14:21 cache
The httpd_sys_rw_content shows that the dir or file is writeable.


In case this is not given execute

sudo chcon -R -t httpd_sys_rw_content_t /full_path_of_dataroot
This will change the file context recursively to the type httpd read/write.


Reload the webpage.





Average of ratings: Useful (1)
In reply to 06S01at14163 itservice

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Dean Thayer -

If you have SELinux enabled, this advice from 06S01at14163 itservice is excellent. You may find that your next problem after configuring SELinux to allow write access to $CFG->dataroot will be a database connection failure. If so, you will need to configure SELinux to allow httpd to connect to your database with this command:

setsebool -P httpd_can_network_connect_db on

I also recommend this article from Red Hat and this article from Oracle for more on how to succeed with SELinux on LAMP servers.

In reply to Atson Nakayama

Re: Data directory cannot be created by installer(c:/inetpub/wwwroot/moodledata)

by Gopal Sharma -
Picture of Plugin developers Picture of Testers

As Emma rightly pointed out this, your ownership of files and dir are not correct.

You must check the ownership of the folder  make sure that user:group 

sudo chown user:group  filename

sudo -R chown user:group  dir

// Directories:

sudo find . -type d -exec chmod XXX {} \;

// Files:

sudo find . -type f -exec chmod XXX {} \;

 For folder/directory should have  755 permission and files 644