The official recommendation from Magento for the permissions of the installation directory is:
- Owner: Read, write, and execute.
- Group: Read, write, and execute.
- Others: Read and execute.
For files, they are:
- Owner: Read and write.
- Group: Read and execute.
- Others: Read only.
You can review this in the official Magento documentation by clicking here.
Directory ownership
If we use another user to perform certain actions in the directory, this may cause the owner/group to change. In that case, you will need to change it back to the web user.
To change the directory ownership recursively, you can run:
# chown -R www-data:www-data /var/www/html/magento2
The web user and path shown are those used by default by the preinstalled Magento image. If you installed Magento in a different directory and/or use another user, you will need to modify the example command.
Directory and file permissions
If permissions are changed, we will need to correct them to ensure proper operation and security. To do this, first access the Magento directory:
# cd /var/www/html/magento2
Next, change the permissions of the files within the directory:
# find . -type f -exec chmod 664 {} \; && chmod u+x bin/magento
Then, change the directory permissions:
# find . -type d -exec chmod 775 {} \;
Additionally, you can allow changes to some files in directories:
# find var pub/static pub/media app/etc -type f -exec chmod g+w {} \;
And also change the permissions of those directories:
# find var pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
Finally, you will need to allow execution of the Magento binary:
# chmod u+x bin/magento
We hope this article has been helpful. If you have questions about this or any other issue related to your servers on Clouding, feel free to contact soporte@clouding.io. We're here to help!