Magento 2.4.2-p1
Smartwave Porto theme
extensions from Amasty

We have the Smartwave Porto theme. It came with Mageplaza Layered Navigation but an old version. Since we have some problems that I raised with Smartwave Porto, they suggested I would upgrade to the latest Mageplaza Layered Navigation version = layered-navigation_v4.1.1_m2_ce_mageplaza.

I have done that, and when running the following command afterwards:

php bin/magento setup:di:compile

I get this Error:

The directory "/home/myaccount/public_html/generated/code/Magento" cannot be deleted Warning!rmdir(/home/myaccount/public_html/generated/code/Magento): Directory not empty

I asked Mageplaza and said the following:

...please run the command again with adding "sudo" at first.

So I've tried the following:

sudo php bin/magento setup:di:compile

and my Putty says the following:

We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

and asked for the password again. Once I entered the password - it gave the following Error:

myaccount is not in the sudoers file. This incident will be reported.

When googling this topic, I found the following article:


Here it says:

www-data must be owner of the project if using Apache as web-server. Please execute commands given below:

sudo chown -R www-data:www-data [path to magento directory]
navigate to root of your magento project
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find ./var -type d -exec chmod 777 {} \;
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;
chmod 777 ./app/etc
chmod 644 ./app/etc/*.xml
chmod u+x bin/magento

We had a problem with ownership/permissions before. Is it safe for me run these in Putty via SSH on the account itself and/or ask our hosting company to do it for me?

3 Answers 3


You can run the command like this one :

sudo chmod -R 777 var/ generated/ pub/
php bin/magento setup:di:compile
  • This works for me. Thank you.
    – Allysin
    Oct 21, 2021 at 5:16

It's worth checking with your web host to see if the file permissions are set up correctly, however you should try to clear the generated/code directory first. Try clearing the directory manually before running the compile command:

rm -r generated/code/*
php bin/magento setup:di:compile

You can refer to the devdocs for more information about clearing directories during development: https://devdocs.magento.com/guides/v2.4/howdoi/php/php_clear-dirs.html

  • This is a good solution but appears to be temporary as di:compile worked immediately after but the problem reappeared the next day.
    – Allysin
    Oct 21, 2021 at 5:16

Should Change the folder permissions on own via chmod and chown

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.