Magento – Unable to delete Magento 2.0.7 image cache

cachemagento2permissions

When I try to Flush catalog images cache I get the following error

The file

/home/shaffersuiting/public_html/project/pub/media/catalog/product/cache/1/swatch_image/30×20/beff4985b56e3afdbeabfc89641a4582/i/n/inqalab_final_colour_08.jpg

Cannot be deleted

Warning!unlink(/home/shaffersuiting/public_html/project/pub/media/catalog/product/cache/1/swatch_image/30×20/beff4985b56e3afdbeabfc89641a4582/i/n/inqalab_final_colour_08.jpg):
Permission denied

All my folders/files have 775 permission

Help required urgently

Best Answer

Check permissions and ownership of this exact file:

/home/shaffersuiting/public_html/project/pub/media/catalog/product/cache/1/swatch_image/30x20/beff4985b56e3afdbeabfc89641a4582/i/n/inqalab_final_colour_08.jpg

Try deleting it manually and clearing image cache again.

It you can't delete it manually, I presume 2 situation might have caused such behaviour:

  1. you deployed static files with root privilages - so all files in your /pub/ folder have root owner and can't be deleted by the Magento file system owner.

  2. Your web server is missconfigured so the Magento file system owner doesn't have write permissions on these files - in this situation as a quick fix you'd need to give 777 permission to all your files, which is a bad idea overall.

The 1st situation is more likely, so you'd need to run:

sudo chown file_system_owner:file_system_owner /home/shaffersuiting/public_html/project/pub/ -R

Where "file_system_owner" is the owner of Magento root.

Related Topic