After installing Magento 2.4.1 I am getting this error:

Exception #0 (DomainException): Unable to write file into directory /var/www/html/magento2/pub/media/catalog/product/cache/912eee9e4cfa9553368073a74de060ea/m/b. Access forbidden.

I have manually installed the sample data for 2.4.1 version and when clicking on the product detail page, this error appears.

2 Answers 2


It is possible that this directory doesn't have the appropriate permissions.

Try sudo chmod 777 /var/www/html/magento2/pub/*

If that doesn't work, I use this code when all else fails.


rm -rf /var/www/html/mage/view_preprocessed/* && rm -rf /var/www/html/mage/pub/static/frontend/* && rm -rf /var/www/html/mage/generated/code/* && bin/magento setup:upgrade && bin/magento setup:di:compile && bin/magento setup:static-content:deploy -f && bin/magento indexer:reindex && bin/magento cache:flush && chmod -R 777 pub var generated

If neither work then:

Check your var/log files.

  • I did add the right permission to each folder, I tried giving 777 to all the folders but the issue remains there.
    – Bushra
    Oct 2, 2021 at 6:47
  • I added a set of commands that I use when all else fails. Oct 3, 2021 at 0:29
Log in to your SSH/CLI with admin permissions and navigate to the root of your store.
Set permissions to the files: find . -type f -exec chmod 644 {} \;
Set permissions to the directories: find . -type d -exec chmod 755 {} \;
Set permissions to special directories: find ./var -type d -exec chmod 777 {} \;
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;

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.