moodledata permissions not working correctly

moodledata permissions not working correctly

by Wani Joseph -
Number of replies: 6

I'm hosting Moodle installation version 3.3 on GCP (Google Cloud Platform), using additional disks for moodledata directory.

I failure happens on my instance which unmounts my moodledata directory. Now I have mounted the directory back, but I couldn't fix the permissions.

I have gone through a post on how to reset moodle's folder and files permission, you find the link here. however, I couldn't get all my files to work, some of them are working fine, and others are not.

Anyone can help I have already quite a lot of time trying to figure out the solution by myself.

Average of ratings: -
In reply to Wani Joseph

Re: moodledata permissions not working correctly

by Ken Task -
Picture of Particularly helpful Moodlers

Qualification for this response ... have a Google Compute Engine moodle instance using CentOS 7 and  /mnt/data/ for moodledata ... haven't had issues with it.

When you say: '... couldn't get all my files to work, some of them are working fine, and others are not.'

Can you describe?

'SoS', Ken

In reply to Ken Task

Re: moodledata permissions not working correctly

by Wani Joseph -
I'm running debian linux.

when the failure occurs, moodle failed with errors message 'You dont have permission to access $cfg->dataroot', that's why I assumed it's permission problem.

Before setting the moodledata directory permission all the files given the below error.

Failed to load PDF document.

after settings permissions of the moodledata directory and gives the ownership to www-data, some of the files working correctly.

I have run a moosh cli command to check whether my files are corrupted or not. and it's not.
Attachment error.PNG
Attachment success.PNG
In reply to Wani Joseph

Re: moodledata permissions not working correctly

by Wani Joseph -
This is same of working file, and error file
In reply to Wani Joseph

Re: moodledata permissions not working correctly

by Ken Task -
Picture of Particularly helpful Moodlers

Well, you've given screen shots but what of actual command line listings of moodledata ...

cd /path/to/moodledata

ls -d moodledata

cd moodledata

ls -l

everything in moodledata on a Debian box needs to belong to www-data (ownership) and permissions need to be rwx - recursively.

When you set ownerships/permissions did you do those commands recursively?

And your moosh command was what?

Consider turning on debugging to see if moodle has more info to give.

'SoS', Ken

In reply to Ken Task

Re: moodledata permissions not working correctly

by Wani Joseph -

I have attached a snippet on the command cd /moodledata ls -l

I also believe that the following commands loog through the /moodledata and gives ownership to www-data, which is apache user, and allow rwX for all files, and subdirectories

chown -R www-data:www-data /path/to/moodledata

chmod -R u+rwX,g+rwX,o+rwX /path/to/moodledata

find /path/to/moodledata -type d -exec chmod 777 {} \;

find /path/to/moodledata -type f -exec chmod 777 {} \;

The question is am I missing some regarding setting the permissions, or the problem occurs because of another error

Allow PHP debug didn't give so much because the files should open after download.

The moosh command is: moosh file-datacheck


Also if you have any recommendations about debugging the cause of the issue will be much helpful


Attachment moodledata.PNG
In reply to Wani Joseph

Re: moodledata permissions not working correctly

by Ken Task -
Picture of Particularly helpful Moodlers

I failure happens on my instance which unmounts my moodledata directory. Now I have mounted the directory back, but I couldn't fix the permissions.

On my system ... CentOS 7 ..
Mounted as.            Type.                                 Location
/mnt/disks/data     New Linux Native Filesystem (ext4)     SCSI device B

mount command:
mount -o discard,defaults /dev/disk/by-id/google-data /mnt/disks/data

Have no entry in fstab that would automatically attempt mount upon reboot.
Reason ... since mounting is the last operation on reboot, if it fails, server
un-accessible.  Discovered that on an unfortunate update RedHat had pushed out to protect vs a flaw (now I don't recall what that was! :\). So rather than have an entry in fstab, i have to run a script to mount it.

Mine:
df -h
/dev/sda1        10G  8.3G  1.8G  83% /
/dev/sdb        493G   42G  426G   9% /mnt/disks/data

Yours?

You mentioned you had to remount after loosing it for some reason.

Might review:
https://cloud.google.com/compute/docs/disks/add-persistent-disk

Note there are permissions involved for the entire disk.
chmod a+w /mnt/disks/MOUNT_DIR

Mine:
ls -ld /mnt/disks/data/
drwxrwxrwx root:root

Yours?

So you are saying a PDF file is found, but when downloading and attempting to open it declares an error at that point?

Any filesystem is not beyond corruption ... maybe not total system but only certain files.

Use mysql query to find contenthash and filename for all files in mdl_files table that have a .pdf extenstion.

Use contenthash value to copy a PDF file that normally gives you that error out of moodledata/filedir/xx/yy/contenthashvalue to a humanly recognizable filename (like test.pdf) to apache document root.   URL to it then would be https://yoursite/test.pdf

What happens?

If you cannot open file in browser or whatever application your browser uses to open a PDF, moodle won't be able to fix a corrupted file ... period.

'SoS', Ken