Magento 2 – Folder/file permissions

Many times when we put into production an online stroe that we have developed locally in Magento 2 (or when we migrate a Magento store from one hosting to another), it may happen that that the permissions got messed up and the store won’t work. The solution will be to correct the file and folder permissions taking into account:

  • The owner of the Magento file system must not be the web server user; it should be a different user.
  • The web server user must have write access to the following files and directories:
    • var
    • app/etc
    • pub
    • generated
  • The owner of the Magento file system must have full control (read/write/execute) of all files and directories.

In addition, as we can read in Magento’s docs, we must restore the file and folder permissions through an ssh access to our server, and use the following commands in the root folder of our Magento installation (for example, if our Magento code is inside magento folder in our server):

cd magento
find . -type f -exec chmod 644 {} \; // 644 permisos para ficheros
find . -type d -exec chmod 755 {} \; // 755 permisos para directorios
find ./var -type d -exec chmod 777 {} \; // 777 permission for var folder
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;
chmod 777 ./app/etc
chmod 644 ./app/etc/*.xml
chown -R : .
chmod u+x bin/magento

Once the permissions are restored, our online store should work again.


Header photo by Clark Young on Unsplash

No Comments

Post a Comment

He leído y acepto la política de privacidad *

Tell us about your project and we will make it happen

Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información.

Aviso de cookies