Magento – Magento 2: Permission issue with generated directory

awsinstallationmagento2permissionstheme

I'm having issues installing a theme due to the 'generated' directory not generating all of the files that need to be generated after I run command:

php bin/magento setup:upgrade

Which I think is linked to permission issues (the generated directories have a default permission set to 775).

Because the generated folders are set to 775 permission, there is no 'write' permission for the other user (magento) and thus crashes instead of upgrading the new theme/modules.

I cannot run the command line as a root user as it uses cgi/fgi instead of cli. I end up having to run as the centos user which uses cli (magento's command line interface) If I could run cli commands as root user. I that would overcome the permission issues that prevents the 'generated' directory from generating all of the files and thus install modules and themes instead of throwing script errors.

I know magento 2.2.6 is relatively new and I'm probably facing an isolated issue given that the environment I'm running magento on is unique: aws instance with whm in the middle to provide greater flexibility and provide a cpanel interface.

Best Answer

Magento 2 recommended folder and file permission

Please follow following terminal commands for folder and file permission.

find . -type f -exec chmod 644 {} \;

find . -type d -exec chmod 755 {} \;

find var pub/static pub/media  generated/ app/etc -type f -exec chmod g+w {} \;

find var pub/static pub/media generated/ app/etc -type d -exec chmod g+ws {} \;
chown -R :<web server group> .

chmod u+x bin/magento

It worked like charm

Related Topic