Error code: storedfilecannotcreatefiledirs from Moodle 3.9

Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Tanky Tang -
Number of replies: 10

Hi i upgrade to Moodle 3.9 from 2.7 so i need to clean install the 3.9 moodle then FTP to custom code through FTP / git pull

after i successfully deply the code and database, i can login the Moodle 3.9 but cannot upload any file through the upload controller.

Below is the error after i type "file" under Site Administration  search

**********

Warning: mkdir(): Permission denied in /var/www/html/wwwroot/lib/filestorage/file_system_filedir.php on line 441

Can not create local file pool directories, please verify permissions in dataroot.

More information about this error

Debug info:
Error code: storedfilecannotcreatefiledirs
Stack trace:
  • line 443 of /lib/filestorage/file_system_filedir.php: file_exception thrown
  • line 1805 of /lib/filestorage/file_storage.php: call to file_system_filedir->add_file_from_string()
  • line 986 of /lib/filestorage/file_storage.php: call to file_storage->add_string_to_pool()
  • line 1167 of /lib/filestorage/file_storage.php: call to file_storage->create_directory()
  • line 420 of /lib/filelib.php: call to file_storage->create_file_from_storedfile()
  • line 10512 of /lib/adminlib.php: call to file_prepare_draft_area()
  • line 8797 of /lib/adminlib.php: call to admin_setting_configstoredfile->output_html()
  • line 76 of /admin/search.php: call to admin_search_settings_html()

**************

Below is the error when i click Site Administrator > Theme

************

Can not create local file pool directories, please verify permissions in dataroot.

More information about this error

Debug info:
Error code: storedfilecannotcreatefiledirs
Stack trace:
  • line 443 of /lib/filestorage/file_system_filedir.php: file_exception thrown
  • line 1805 of /lib/filestorage/file_storage.php: call to file_system_filedir->add_file_from_string()
  • line 986 of /lib/filestorage/file_storage.php: call to file_storage->add_string_to_pool()
  • line 1167 of /lib/filestorage/file_storage.php: call to file_storage->create_directory()
  • line 420 of /lib/filelib.php: call to file_storage->create_file_from_storedfile()
  • line 10512 of /lib/adminlib.php: call to file_prepare_draft_area()
  • line 114 of /admin/category.php: call to admin_setting_configstoredfile->output_html()
Output buffer: <?php<?php<br /> <b>Warning</b>: mkdir(): Permission denied in <b>/var/www/html/wwwroot/lib/filestorage/file_system_filedir.php</b> on line <b>441</b><br />

*********************

The environment is CentOS 7 and Apache 2.4 and PHP 7.2 and MariaDB 10

I have tried to amend all permission through

chmod 0775 -R /moodledata  (and /<filepath>/moodleroot)

chown -R apache:apache /moodledata  (and /<filepath>/moodleroot)

I have tried chmod 0777 or chown root:root  / root:apache  as well.

But the problem still exist. Does anyone  have a solution to fix?  Thank you very much.

Average of ratings: -
In reply to Tanky Tang

Re: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Ken Task -
Picture of Particularly helpful Moodlers

On CentOS 7 the typical 'home' directory for apache is /var/www/

Good place for moodledata is in /var/www/

Document root ... where apps and web pages go is typically /var/www/html/   Your error shows you moodle is looking in

/var/www/html/wwwroot/

Current location for moodledata is in your config.php file which should be found in in /var/www/html/wwwroot/ according to above.

When you change ownerships permissions on folders you need to give full path to folder ... what you've shared you issued is perhaps in-correct as your shell will not understand nor know about a moodle variable.

So ... with moodledata in /var/www/ and the path to moodledata in config.php in code root, the commands to change ownership/permissions would be:

cd /var/www/ (moodledata located there)

chown apache:apache moodledata -R

and permissions (which can be very liberal due to location in /var/www/) could be set via:

chmod ugo+rwx moodledata -R

'SoS', Ken


In reply to Ken Task

回應: Re: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Tanky Tang -
Dear Ken,

Thank you for your reply. It may be my poor explanation in my past thread as I tried to use variable.

the moodledata (named "dataroot") is located at the root path

/dataroot/

whereas moodle file (named "wwwrooot") is located at apache web root path

/var/www/html/wwwroot/

So i have tried below:

[root@host /]# chown apache:apache dataroot -R
# chmod 0777 dataroot -R
# chown apache:apache /dataroot -R
# chown apache:apache /dataroot/ -R

But still cannot upload file
as
Error
Can not create local file pool directories, please verify permissions in dataroot.
URL: <domain>/wwwroot/
Debug info: Error code: storedfilecannotcreatefiledirs

Stack trace:

* line 374 of /lib/filestorage/file_system_filedir.php: file_exception thrown
* line 1794 of /lib/filestorage/file_storage.php: call to file_system_filedir->add_file_from_path()
* line 1323 of /lib/filestorage/file_storage.php: call to file_storage->add_file_to_pool()
* line 229 of /repository/upload/lib.php: call to file_storage->create_file_from_pathname()
* line 63 of /repository/upload/lib.php: call to repository_upload->process_upload()
* line 324 of /repository/repository_ajax.php: call to repository_upload->upload()



In reply to Tanky Tang

回應: Re: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Tanky Tang -
We did not move the folder path as at clean install

/dataroot/
/var/www/html/wwwroot/

which is successful and also can upload file in the clean install 3.9

then we upload the custom-made and modified php files by SFTP
In reply to Tanky Tang

Re: 回應: Re: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Ken Task -
Picture of Particularly helpful Moodlers

Am not following now ... so you fixed it?

'SoS', Ken

In reply to Ken Task

回應: Re: 回應: Re: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Tanky Tang -
Hi Ken,

Unfortunately no.

Does the path of dataroot access need to define in Apache? We do not modify the http.conf

The mysterious is clean install is working, but after we upload the dataroot and wwwroot through FTP is not.

The development server (Windows + Xampp) is working normally.

S.O.S. Thanks.
In reply to Tanky Tang

Re: 回應: Re: 回應: Re: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Ken Task -
Picture of Particularly helpful Moodlers

Errr ... ok I see the 'fly in the onitment' ... 'development server Windows + Xampp'.

CentOS 7 isn't Windows and one really shouldn't equate xampp to a CentOS 7 AMP stack.

So ... having said that ...

The moodledata directory (your dataroot) should be in /var/www/

Your moodle code should be in /var/www/html/ ...

Apache server is already configured to know that apache root is in /var/www/ (that's why moodledata [your dataroot] should be located there) ... nothing special but ownerships and permissions need be done to moodledata (your dataroot) if located in /var/www/.

The moodle code from an unzipped download will create a moodle directory.   On your server now you've said you have the moodle code in /var/www/html/webroot/ .... for apache to serve that out via http://yoursite/ you have to had edited httpd.conf of apache and redefined 'documentroot' as /var/www/html/webroot/

Apache's default 'documentroot' *is* /var/www/html/

Put the code of moodle in /var/www/html/

To move the data directory contents (your dataroot) use the mv command:

mv /dataroot/ /var/www/moodledata

you will have to edit config.php to give moodle that datadirectory path ... which will be /var/www/moodledata/

Owerships permissions

cd /var/www/

with your dataroot now named moodledata

chown apache:apache /var/www/moodledata -R

permissions

chmod ugo+rwx /var/www/moodledata -R

The one thing about CentOS 7 that always trips up folks is seLinux (Security  Enhanced Linux) which doesn't come with Windows/XAMP

Suggest turning it to permissive for now ... as root user in ssh shell on CentOS 7 server:

First see of selinux running:

sestatus [ENTER]

Do you see: Current mode set to enforcing?

Set it to 'permissive'.

See:

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/using_selinux/changing-selinux-states-and-modes_using-selinux

'SoS', Ken




In reply to Tanky Tang

Re: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi

You wrote:
> i upgrade to Moodle 3.9 from 2.7 so i need to clean install the 3.9 moodle

https://docs.moodle.org/39/en/Installing_Moodle and https://docs.moodle.org/39/en/Moodle_migration are two different things.
In reply to Visvanath Ratnaweera

回應: Re: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Tanky Tang -
Hi Visanath,

Thanks for your reply.

As we custom modify the 2.7+ version heavily before, so we cannot do direct migration follow the normal procedures.

What we did in migration :
1) clone 2.7 from production to localhost
2) clean install 3.9 in localhost
3) compare 2.7 custom code and add to 3.9 as block/extend/plugin (and related database update as well)
4) test in work normally in localhost
5) after finish the development, we git pull code to dedicated server
6) update the database in dedicated server
7) testing in dedicated server

it work normally (login, add course/ db record, etc) but just cannot update ANY files.

So we add

4.1) clean install 3.9 in dedicated server
4.2) test upload function under clean install 3.9
4.3) work perfectly (dataroot and wwwroot is the same location by clean install or FTP uploaded code)

but the file upload problem still exist
In reply to Tanky Tang

Re: 回應: Re: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi

I can't comment on how to merge the code changes. Even on core Moodle there is no straight upgrade to rel. 3.9 from 2.7. See the second column in the table http://www.syndrega.ch/blog/#php-and-dbms-compatibility-of-major-moodle-releases.

Also notice that the system software involved, most notably PHP, also have min. and max. releases. (Also visible in the table mentioned.)
In reply to Tanky Tang

回應: Error code: storedfilecannotcreatefiledirs from Moodle 3.9

by Tanky Tang -
hi,

Finally I figure out the problem and fixed

Somehow our old 2.7 has connect to FTP server, and set the file dir path in config.php

$CFG->filedir = '';

And after we set the folder to 777, the problem solve.

Thank you very much for your time.