1

I keep getting the following types of errors:

Exception #0 (Exception): Warning: file_put_contents(/opt/magento2ce/var/cache//mage-tags/mage---3d0_TRANSLATE): failed to open stream: Permission denied in /opt/magento2ce/vendor/colinmollenhour/cache-backend-file/File.php on line 663

and

Something went wrong while saving this configuration: Warning: is_file() expects parameter 1 to be a valid path, string given in /opt/magento2ce/vendor/colinmollenhour/cache-backend-file/File.php on line 512

Originally I noticed a problem only when applying new themes. After doing more testing, the issue seems to only happen when bin/magento setup:upgrade or bin/magento setup:di:compile is run. Both are being run as the correct file system owner appsuser. And there are no errors in the console output when these commands are run. For reference here is web server user and checking groups from root:

# ps aux | grep nginx
root     23987  0.0  0.0  14224   992 pts/0    S+   18:18   0:00 grep --color=auto nginx
root     26437  0.0  0.0 125928  1740 ?        Ss   18:01   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 26438  0.0  0.1 126304  5740 ?        S    18:01   0:00 nginx: worker process
www-data 26439  0.0  0.0 125928  3392 ?        S    18:01   0:00 nginx: worker process
www-data 26440  0.0  0.1 126460  6060 ?        S    18:01   0:00 nginx: worker process
www-data 26441  0.0  0.0 125928  3392 ?        S    18:01   0:00 nginx: worker process


# groups appsuser 
appsuser : appsuser www-data

The permissions that end up wrong are always in var/cache/mage-tags/ They have the web server file owner as the user and group owner (appsuser:appsuser) when it should be appsuser:www-data like the rest of '/opt/magento2ce/` directory. All other files get created with correct user and group.

Running the following always resolves the issue (modified from ref "install & configure Magento2" #3 from here ):
chown -R :www-data var/cache/mage-tags/

I don't understand how all newly generated files in var/cache/* except var/cache/mage-tags/* end up with the correct permissions. I even have the SGID set with chmod -R g+s /opt/magento2ce/ and the /opt/magento2ce/var/cache/mage-tags/* directory still ends up doing its own thing.

Does anybody have a permanent fix for this?

The original setup process i used for install is here and here. I modified accordingly because this is hosted on a multi-user system that had an existing web server user and group.

There is a thread that was closed here with original details.

Similar issue here and here

3
  • I have a similar error, but at vendor/colinmollenhour/cache-backend-file/File.php on 663 and 646. The command chown -R :www-data var/cache/mage-tags/ fixed the problem as it did for you. Feb 13, 2018 at 23:44
  • You need to (1) sudo usermod -aG www-data appuser (2) restart your system (3) on magento project root folder "find var -type -exec chmod g+w {} \;" (4) on root folder of magento project "find var generated pub/static pub/media -type d -exec chmod g+sw {} \;" I have tested it on the Magento EE 2.3
    – Abbas
    Jul 2, 2019 at 4:59
  • @Abbas thank you for your solution, its working
    – wightman
    Dec 23, 2021 at 16:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.