Magento 2 Error – Unable to Write File into Directory

errormagento-communitymagento2sample-data

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.

Best Answer

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.

Try:

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.