In the installations manual https://docs.moodle.org/403/en/Installing_Moodle
i find 2 different chown commands.
chown -R root /path/to/moodle
vs
chown www-data /path/to/moodle
Im logged in as root at a fresh installed ubuntu 22.04 cloud server.
What is the right command or what is the difference?
It is, however, acceptable on a local test/development server where you might want to make use of the plugin installation and upgrades. Just to be clear I would definitely not set up a live Moodle site such that installing or updating plugins through the admin interface was allowed. A very bad idea.
root
and www-data
refer to the user who will own the files.
root
is the main administrative account for the server. www-data
is in this case the user that the web server (apache or nginx) runs as.
In the first case, the example is setting ownership and permissions of the Moodle code files so that www-data
cannot modify them. This is a security precaution to prevent someone accessing your site via the web from altering the PHP code. When a user makes a request, the code runs on your server as the www-data
user so you don't want that user being able to change the code that runs.
In the second case, you are setting ownership and permissions of Moodle's data directory so that www-data
can modify them. This is where files uploaded by users will be stored, so the www-data
need to be able able to write them to a directory.
Or does in the backup process (after copying the new files and proceed the backup with the browser) /var/www/html/moodle other rghts?
This command changes the owner of the /path/to/moodle directory and all its subdirectories and files to the root user.
2. chown www-data /path/to/moodle:
This command changes the owner of the /path/to/moodle directory and its contents to the www-data user. This is typically associated with web servers like Apache or Nginx on your Ubuntu.
So its it's recommended to use
chown -R www-data /path/to/moodle
Secure the Moodle files: It is vital that the files are not writeable by the web server user.
Which is exactly what chown -R www-data /path/to/moodle chmod 0755 /path/to/moodle will do.
If the owner is set to root instead, www-data will have read and execute only as an "other".
Installing plugins will not a temporary permission change.
The temptation / rookie mistake is to install an untested plugin AND to run the upgrade script without first taking a backup. Both of which might end in tears.
- Advise the owner of Moodle code should be root
- Advise the owner of Moodle code should be www-data
- Explain under what circumstances root or www-data should be used
- Do nothing to our documentation because it is too difficult and cope with confused installers through describing Linux commands on this forum.
I don't believe we should "spoon feed" advice like this. We can give general guidance but if you are going to run a live Moodle site on the public Internet then you have some responsibility to know what you are doing. Advice is happily and freely given in these forums but it all depends on your circumstances and requirements.
Even taking somebody through a "click by click" installation for a particular OS isn't much better than just saying "use Softaculous, then". There's more to running a server than getting Moodle to work.
Forums like this helped me to learn from scratch
- to admin a php forum for my sales team
- switching from Windows to Linux Mint last year
- and last week i was so brave to ordered a cloud server on hetzner and was able to run Mautic (sales automatic system for e-mail newsletter and so on) and now Moodle runs. I'm proud of myself to were able to install this. Was not so easy as a newbie and took a long time to look the youtube tutorials or read the install docs.
I'm not programmer - i'm still a person, who likes independence and security for my data and my content.
i only was able because of help of people like you.
Thanks a lot.