Magento 2 below the Warning come.

Warning: file_put_contents(/var/www/html/var/cache//mage-tags/mage---792_CONFIG): 
failed to open stream: Permission denied in /var/www/html/vendor/colinmollenhour/cache-backend-file/File.php on line 663

Please Help.

After changing permissions I got an error "Class Magento\Review\Model\ReviewFactory does not exist"

Ok, I fixed above error by deleting generation folder and making static content deploy

  • 2
    var folder should have write permission.
    – Sohel Rana
    Commented Oct 19, 2016 at 7:32
  • run commands as sudo Commented Feb 2, 2017 at 19:22
  • 1
    I have the same problem. I can fix it by running a chmod command, but it reoccurs when I run cache:clean or someting else. I think the real problem is some extension that sets the permissions wrong. But how can we fix that?
    – Rick
    Commented Jul 24, 2018 at 8:49
  • I got the same issue even after assigning permission, the issue keeps appearing
    – devendrant
    Commented Jan 1, 2021 at 6:44

8 Answers 8


Magento told you that you don't have permissions to write in /var/cache folder, please check what are the permission of the /var folder.

Overview of ownership and permissions Magento 2


I tried with sudo bin/magento setup:di:compile and works fine.


You can try changing all permissions by using the following command

sudo find . -type d -exec chmod 755 {} \; 
sudo find . -type f -exec chmod 644 {} \;

I know it's not the prettiest solutions, but it worked for me.

  • 1
    After i run these commands, i am getting the fatal error and not writable error Commented Jan 4, 2020 at 6:23

you have a permission problem

Fix it by using this cmd : chmod 755 -R var/*


I think it's not a bug, I experienced the same after running the cache: clean command as root user.

So by applying for the file permission again, this issue has been fixed. http://devdocs.magento.com/guides/v2.2/install-gde/prereq/file-sys-perms-over.html

So be careful don't clean the cache as root/sudo user


For anyone that has recently had this problem. I fixed this in my staging environment by running the chmod 755 -R var/* command, but make sure you do it to the /var directory and not /var/www/html/var. Hope it makes sense. I am quiet new to Linux so it took a while for me to get my head around.

This is also a very important reard https://devdocs.magento.com/guides/v2.3/install-gde/prereq/file-sys-perms-over.html


The below fixed my problem, and magento runs very smooth ever.

find . -type f -exec chmod 664 {} \;

find . -type d -exec chmod 775 {} \;

find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +

find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +

//Change the ownership to your Magento user
sudo chown -R <Magento user>:<web server group> .

//<web server group> usually will be www-data

Try this will fix chmod 777 -R var/*

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.