Magento or Apache 2 – Fix File Permissions Issue

apacheApache2clifile-permissionspermissions

I have a vm where I run ubuntu 18.04 , Apache 2 and Magento 2.3 every thing works fine but I think I'm doing something wrong with my permissions.

So I have added to user 'dev' to the www-data group (dev is also the sudo user that I use to login )

but when I do

sudo chown -R  dev:www-data /var/www 

My Magento site stops working because it complains it has not access to the files.
but when I run

sudo chown -R  www-data:www-data /var/www 

All work fine again and I don't understand why, because the user dev is added to the www-data group so it should have the wright permissions.

or should I run

sudo chown -R dev:www-data /var 

I don't know?????

Best Answer

Set Magento permission :-

sudo find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \;
sudo find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
sudo chown -R :www-data .
sudo chmod u+x bin/magento
sudo chmod -R 777 pub var app/etc setup generated

After follow magento step you need to give permission to these folder :-

sudo chmod -R 0777 var/ generated/code/ pub/static
Related Topic