I get "The requested class did not generate properly, because the 'generated' directory permission is read-only" during setup:di:compile even though the folder has 777 permission.

I even tried with sudo, but I get the same error.

3 Answers 3


Try this command from CLI.

sudo chmod -R 777 var/ generated/

  • It is already set as 777, both var and generated.
    – Black
    Commented Dec 30, 2022 at 13:47
  • Does that set properly? or it reset automatically when site is load on frontend? Commented Jan 2, 2023 at 10:03

Try below setps and check.

rm -rf pub/static/frontend/ pub/static/adminhtml/ var/{cache,composer_home,page_cache,view_preprocesseds,di} generated/*

sudo php bin/magento setup:upgrade

sudo php bin/magento setup:di:compile

sudo chmod -R 777 var/ generated/ pub/

Let me know if any query.


  1. Remove generated directory with the root user.

    sudo rm -rf generated

  2. Then switch to the Web server user (typically, it is www-data)

  3. Finally, compile code:

    bin/magento setup:di:compile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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