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– Black2022年12月30日 13:47:29 +00:00Commented Dec 30, 2022 at 13:47
- 
 Does that set properly? or it reset automatically when site is load on frontend?Dhiren Vasoya– Dhiren Vasoya2023年01月02日 10:03:03 +00:00Commented 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.
THANKS.
- Remove generated directory with the root user. - sudo rm -rf generated
- Then switch to the Web server user (typically, it is www-data) 
- Finally, compile code: - bin/magento setup:di:compile