2

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.

  • This is exactly why Magento says you should setup Magento2 as a user on the server that has the correct group and permissions – Haim Nov 19 '18 at 5:04
2

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

1

It' sometimes happen, that after run any command bin/magento your generated folder has changed ovnership to youruser:youruser, but should be youruser:www-data (for apache2 for example).

To fix that run in magento directory:

sudo chown -R youruser:www-data .

and:

sudo usermod -a -G www-data youruser

after this you will never have this problem after running magento commands.

The -a -G options are important because they add apache or www-data as a secondary group to the user account, which preserves the user’s primary group. Adding a secondary group to a user account helps restrict file ownership and permissions to ensure members of a shared group only have access to certain files.

You can check this by running now:

php bin/magento c:f


ls -l generated/code

all ovnership should stay same so youruser:www-data

Ref: https://devdocs.magento.com/guides/v2.3/install-gde/prereq/file-system-perms.html

0

Give 777 permission to 'generated' directory

0

sudo chown -R $(whoami) YOUR_PROJECT_FOLDER && sudo chmod -R 777 YOUR_PROJECT_FOLDER

0

You must read this article from Magento Devdocs, where say exactly what you want about the permissions.

cd /var/www/html/magento2 && find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var vendor pub/static pub/media app/etc -type d -exec chmod g+w {} + && chmod u+x bin/magento

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.