0

How to fix missing permissions?

I'm using Magento 2.2.3.

Switched from production mode back to developer mode missing generated, var, pub permissions

Step 1

rm -rf generated/metadata/* generated/code/*
php bin/magento deploy:mode:set developer

And then ran php bin/magento setup:upgrade command. After running the command it will miss permissions again. How I can fix and don't miss the permission again?

Thank you!

sudo chmod -R -v 777 generated
sudo chmod -R -v 777 var
sudo chmod -R -v 777 pub

Before switching from developer mode to production mode command was running without any problem.

php bin/magento deploy:mode:set production -s --skip-compilation
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento indexer:reindex
php bin/magento setup:static-content:deploy

Now, I want back to developer mode but getting so many errors like:

main.CRITICAL: Can't create directory public_html/generated/code/Magento/Framework/App/Http/. in [Magento\Framework\App\Http\Interceptor] {"exception":"[object] (RuntimeException(code: 0): Can't create directory public_html/generated/code/Magento/Framework/App/Http/. in [Magento\\Framework\\App\\Http\\Interceptor] at public_html/vendor/magento/framework/Code/Generator.php:115)"} []

please let me know how I can fix it. Thank you very much!

  • Are all the files/dir owner the same? And are they the same as the magento user? – Spencer Rohan Mar 4 '18 at 18:07
2

Might be it is happening because you are running commands with root user. If you will run commands with root user or sudo then it changes the owner and group user to root.

Assigning 777 permission is not the good way,because it provides read and write permission to root user,group and others. What we need to do is , provide read write permission to user which needs it. So give permission 774 It means owner and group users will have read and write permission .

Now what you need to do is assign var,pub and generated directories to correct owner and group.command is as below

sudo chown -R owneruser:group directory

Most of the servers use www-data group because web user is assigned in www-data group. Here is the example command sudo chown -R root:www-data var generated pub/static

In above command owner is root user you can use your ssh user at place of root.

You need to run above command according to your need.

0

I guess you are using private server and having multiple or more than 1 user. You need to follow the Magento instruction on how to set the permission on the server to fix your issue.

http://devdocs.magento.com/guides/v2.2/config-guide/prod/prod_file-sys-perms.html

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.