upgrade from 3.1.15 to 3.5.4 throws "Invalid permissions detected when trying to create a directory" error

upgrade from 3.1.15 to 3.5.4 throws "Invalid permissions detected when trying to create a directory" error

by Benoît M -
Number of replies: 7

Hi, I am encountering the following trying to upgrade from moodle 3.1.15 to 3.5.4.

Invalid permissions detected when trying to create a directory. Turn debugging on for further details.
Debug info: [cachedir]/cachestore_file/default_application is not writable, check permissions.
Error code: invaliddatarootpermissions
Stack trace:

    line 1566 of /lib/setuplib.php: invalid_dataroot_permissions thrown
    line 1744 of /lib/setuplib.php: call to make_writable_directory()
    line 155 of /cache/stores/file/lib.php: call to make_cache_directory()
    line 528 of /cache/classes/helper.php: call to cachestore_file->__construct()
    line 493 of /cache/classes/helper.php: call to cache_helper::purge_store()
    line 1655 of /lib/moodlelib.php: call to cache_helper::purge_all()
    line 331 of /admin/index.php: call to purge_all_caches()



moodledata folder is located at:

$CFG->dataroot = "/var/www/moodledata/";


Permissions should work:

ls -l /var/www/     
total 8
drwxrwxrwx 51 www-data www-data 4096 Mar 21 13:27 html
drwxrwxrwx 10 www-data www-data 4096 Mar 20 12:40 moodledata

I upgrade from php 5.6 to 7.0 too.


Any idea?
Cheers,
Ben

Average of ratings: -
In reply to Benoît M

Re: upgrade from 3.1.15 to 3.5.4 throws "Invalid permissions detected when trying to create a directory" error

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

If you haven't changed anything, you're looking at

/var/www/moodledata/cache/cachestore_file/default_application

What are the permissions for that directory?

To save any messing around, you might want to just completely delete /var/www/moodledata/cache (it's perfectly safe)

In reply to Howard Miller

Re: upgrade from 3.1.15 to 3.5.4 throws "Invalid permissions detected when trying to create a directory" error

by Benoît M -

that's really strange. If I take a look at the latest files written by www-data user in moodledata/cache and moodledata/localcache, permissions are not as expected :

root@703c675cab39:/# ls -ltr /var/www/moodledata/cache/
total 364
-r-------- 1 www-data www-data 367528 Mar 21 14:28 core_component.php
dr----x--t 2 www-data www-data   4096 Mar 21 14:28 cachestore_file




root@703c675cab39:/# ls -ltr /var/www/moodledata/localcache/
total 4
dr----x--t 2 www-data www-data 4096 Mar 21 14:28 mustache


in config.php

$CFG->directorypermissions = '0777';



I tried to delete them but these folders are re-created with bad permissions triggering error:

root@703c675cab39:/# rm -rf /var/www/moodledata/localcache/
root@703c675cab39:/# rm -rf /var/www/moodledata/cache/   

root@703c675cab39:/# ls -ltr /var/www/moodledata/          
total 36
drwxrwxrwx   4 www-data www-data 4096 Mar 18 10:54 lang
drwxrwxrwx   2 www-data www-data 4096 Mar 18 10:54 muc
drwxrwxrwx   6 www-data www-data 4096 Mar 18 10:54 temp
drwxrwxrwx   4 www-data www-data 4096 Mar 18 10:54 trashdir
drwxrwxrwx   2 www-data www-data 4096 Mar 18 10:54 upgradelogs
drwxrwxrwx 258 www-data www-data 4096 Mar 18 12:03 filedir
dr----x--t   2 www-data www-data 4096 Mar 21 14:36 cache
dr----x--t   2 www-data www-data 4096 Mar 21 14:36 localcache


So it seems that apache2 does not create folder with the right permissions and I don't know why.
Any help would be appreciated.

In reply to Benoît M

Re: upgrade from 3.1.15 to 3.5.4 throws "Invalid permissions detected when trying to create a directory" error

by Benoît M -

I am debugging.

I add this 2 lines in config.php:


mkdir("/var/www/moodledata/foo", 0777);
mkdir("/var/www/moodledata/bar", 777);


which give:

root@28688cca5172:/# ls -ld /var/www/moodledata/foo
drwxr-xr-x 2 www-data www-data 4096 Mar 21 15:14 /var/www/moodledata/foo
root@28688cca5172:/# ls -ld /var/www/moodledata/bar
dr----x--t 2 www-data www-data 4096 Mar 21 15:14 /var/www/moodledata/bar


to be continued...

In reply to Howard Miller

Re: upgrade from 3.1.15 to 3.5.4 throws "Invalid permissions detected when trying to create a directory" error

by Benoît M -

hi Howard, you will find the directory permissions :

root@703c675cab39:/# ls -ld /var/www/moodledata/localcache/
dr----x--t 2 www-data www-data 4096 Mar 21 14:36 /var/www/moodledata/localcache/
root@703c675cab39:/# ls -l /var/www/moodledata/localcache/
total 0


root@703c675cab39:/# ls -ld /var/www/moodledata/cache/
dr----x--t 2 www-data www-data 4096 Mar 21 14:36 /var/www/moodledata/cache/
root@703c675cab39:/# ls -l /var/www/moodledata/localcache/
total 0
root@703c675cab39:/#


As you can see, folder have wrong permissions and are empty.

A  chmod , does not change anything:

 chmod -R 777 /var/www/moodledata/
In reply to Benoît M

Re: upgrade from 3.1.15 to 3.5.4 throws "Invalid permissions detected when trying to create a directory" error

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 I said. Just delete the cache directory and see what happens.

Is the permissions setting correct in config.php

//=========================================================================
// 4. DATA FILES PERMISSIONS
//=========================================================================
// The following parameter sets the permissions of new directories
// created by Moodle within the data directory.  The format is in
// octal format (as used by the Unix utility chmod, for example).
// The default is usually OK, but you may want to change it to 0750
// if you are concerned about world-access to the files (you will need
// to make sure the web server process (eg Apache) can access the files.
// NOTE: the prefixed 0 is important, and don't use quotes.
$CFG->directorypermissions = 02777;
In reply to Howard Miller

Re: upgrade from 3.1.15 to 3.5.4 throws "Invalid permissions detected when trying to create a directory" error

by Benoît M -

Hi Howard,

you're right. There is  a note about the use of quote in config-dist.php

I finally found the root of the issue. It comes from the string value passed to the parameter $CFG->directorypermissions = '0777'.

This one is working:


$CFG->directorypermissions = 0777; //casting problem here ?
var_dump($CFG->directorypermissions);die;

outputs:

int(511)


Whereas this settings throw the error when moodle tries to create folder in cache dirs:

$CFG->directorypermissions = '0777'; //no casting problem here but apache fails when creating cache dirs
var_dump($CFG->directorypermissions);die;


outputs:

string(4) "0777"


This is very confusing to saw that the right you write 0777 is interpreted by php to 511.

Idem for the default value from config.dist.php :

$CFG->directorypermissions = 02777;
var_dump($CFG->directorypermissions);die;
outputs:

int(1535)
cheers,

ben

In reply to Benoît M

Re: upgrade from 3.1.15 to 3.5.4 throws "Invalid permissions detected when trying to create a directory" error

by Alain Raap -
Picture of Particularly helpful Moodlers

Benoit, I created a temp folder outside the moodledata directory and made it writable for the Apache user. There I also put the cache and localcache of Moodle. Maybe that helps for the directory permission problems.

In my config.php file:

$CFG->tempdir   = 'path to your tempdir';
$CFG->cachedir  = $CFG->tempdir.'/cache';
$CFG->localcachedir = $CFG->tempdir.'/localcache';