I have hosted the Magento 2 on a shared hosting server where they recommend to keep all folders as 755 and files as 644. However Magento recommeds to keep 770 for folders and 660 for all files.

As per the recommendation by hosting provider I set as 755 and 644 along with a small hack in the vendor\magento\framework\Filesystem\DriverInterface.php by setting the same 755 and 644.

Majority of the website is working great however I hit file permission problems whenever I want to access anything inside var or media folder.

For Ex:

./bin/magento setup:upgrade

This throws an error saying unable to access var folder.

While googling I found the thread and noticed someone recommending to keep 777 for the below folders.

find ./var -type d -exec chmod 777 {} ;
find ./pub/media -type d -exec chmod 777 {} ;
find ./pub/static -type d -exec chmod 777 {} ;
chmod 777 ./app/etc

Setting this solved my problem however I am worried will that not open any security risk? I do have downloadable files under media. If yes, what is the recommended file permission setup for Magento 2 on a shared hosting server.

  • @TejabhagavanKollepara please flag as duplicate carefully. Both questions are about file permissions, but are different. I understand that the OP of this question is aware of the facts mentioned in the question you are pointing out. This question here is in extend to that question.
    – 7ochem
    Feb 17, 2017 at 9:33

1 Answer 1


Please, check the following links to set the permission properly: http://devdocs.magento.com/guides/v2.0/install-gde/prereq/integrator_install.html http://devdocs.magento.com/guides/v2.0/install-gde/prereq/apache-user.html

Just for summary: Magento team suggest to set the file permissions to 660, the directory ones to 770. It's can be done in the following way sudo find . -type d -exec chmod 770 {} \; && sudo find . -type f -exec chmod 660 {} \; && sudo chmod u+x bin/magento Also, to improve the security of the site you may run your Magento instance by non-root owner.
Here is helpful answers form a post with the same theme: Magento 2 folder/file permissions

  • I did everything as described but when I'm trying to create a new product it gives me an error: {"0":"Can't create directory ....
    – Rob D. A.
    Oct 31, 2017 at 14:45
  • Tried this, now the server 403's "You do not have permission to access this document" sudo chmod +x . Jan 23, 2019 at 21:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.