cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 file system permissions problem

Magento 2 file system permissions problem

For a little while now, I've been dealing with some issues related to file system permissions that are causing problems on the server.  My current setup is as follows:

 

AWS EC2 instance with default user "ubuntu" (ubuntu 16.04 LTS).

Magento 2.2.3 EE

Apache

Installation root /var/www/html/magento2

 

I've followed the instructions here: https://devdocs.magento.com/guides/v2.2/install-gde/prereq/file-system-perms.html

 

But it seems as though it's not sticking, as every time I run 'setup:upgrade' I'm stuck with permissions issues that usually result in a "can't write file" type of output.  I've made sure the ubuntu user is part of the www-group.  I've written a bash script that essentially fixes everything temporarily, but that's obviously not a long term solution (and I've made a few modifications like trying to add a sticky bit on the file / dir permissions).  Here's what it is currently doing.

 

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

cd /var/www/html/magento2

find var vendor generated pub/static pub/media app/etc -type f -exec chmod u+ws {} \;

find var vendor generated pub/static pub/media app/etc -type d -exec chmod u+ws {} \;

chmod u+x bin/magento

 

Running this puts things back into working order, but then if I upgrade I'm back to having issues.  Any help would be appreciated, please let me know if there is any other info I can provide.