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.