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
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/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?
There is a thread that was closed here with original details.