Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save janzikmund/e59abe11806be19dcd07dd44c6a67bed to your computer and use it in GitHub Desktop.
Save janzikmund/e59abe11806be19dcd07dd44c6a67bed to your computer and use it in GitHub Desktop.
Set proper folder permissions on Magento2 installation

Magento2 set proper folder owners and permissions

1. Set www-data as owner and group for all files

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

2. Set group-id bit on system regenerated folders

This is necessary for folders to keep www-data as their group after they are regenerated from command line.

Without this step, the owner would become the sudo user triggering the command (like cache:clean or setup:static-content:deploy), and www-data couldn't write into these folders anymore.

This could probably be avoided seting umask, but that is a server-wide change, while this way it only affects current vhost.

cd /var/www/html
sudo chmod -R g+s pub/static pub/media var/cache var/generation 

More details about this can be found here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment