0

I am having a problem with Magento open source 2.3.4 and its configuration to work with varnish 6. I have followed the devdocs about setting up varnish caching. I have verified that the varnish part works well with nginx and php-fpm by verifying that it works with a small demo page. The only part that is not working is Magento 2.3.4.

The nginx error log shows the following error:

2020/03/03 14:32:34 [error] 7273#7273: *4 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Zend_Cache_Exception: cache_dir "/usr/share/nginx/html/magento2/var/page_cache" is not writable in /usr/share/nginx/html/magento2/vendor/magento/zendframework1/library/Zend/Cache.php:209
Stack trace:
#0 /usr/share/nginx/html/magento2/vendor/magento/zendframework1/library/Zend/Cache/Backend/File.php(180): Zend_Cache::throwException('cache_dir "/usr...')
#1 /usr/share/nginx/html/magento2/vendor/colinmollenhour/cache-backend-file/File.php(87): Zend_Cache_Backend_File->setCacheDir('/usr/share/ngin...')
#2 /usr/share/nginx/html/magento2/vendor/magento/zendframework1/library/Zend/Cache.php(153): Cm_Cache_Backend_File->__construct(Array)
#3 /usr/share/nginx/html/magento2/vendor/magento/zendframework1/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('Cm_Cache_Backen...', Array, true, true)
#4 /usr/share/nginx/html/magento2/vendor/magento/framework/App/Cache/Frontend/Factory.php(156): Zend_Cache::factory('Magento\\Framewo...', 'Cm_Cache_Backen...', Array, Array, true, tr" while reading response header from upstream, client: 127.0.0.1, server: www.example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.example.com"

It is clear that magento thinks it should be using its built in full page cache because it is trying to access var/page_cache. A correct installation using varnish would not be attempting to access this directory.

I have configured magento to use varnish. Does anybody have any insight as to why it is not working correctly?

4 Answers 4

1

you mistaken this functionality.

first of all you must have proper permissions set and access rights, no matter how cache is configured.

second you need to check your app/etc/env.php configuration file, it will tell you exactly where cache and session storage is.

then after you change settings you can manually flush caches to apply new settings

1
  • The permissions on the var/page_cache directory are the same as when I use the built-in cache so the permissions are correct. Mar 3, 2020 at 15:25
1

https://devdocs.magento.com/guides/v2.3/config-guide/varnish/config-varnish.html

According to dev docs as of march 2019 v4 and v5 of varnish are supported. Can anyone confirm version 6 will work?

This could be your problem?

4
  • Magento 2.3 will generate a vcl file for varnish 6 which I assume implies that varnish 6 is supported. I went with the assumption that the docs hadn't been updated. Mar 4, 2020 at 9:26
  • Yes solid assumption. If you figure it out might be worth submitting pull request to dev docs github.com/magento/devdocs save others similar pain Mar 4, 2020 at 19:23
  • I have back ported my ansible script to install varnish v4 and it does not fix the problem. Will submit a fix to devdocs as and when I manage to fix this. Mar 5, 2020 at 9:32
  • Have submitted a documentation fix here. Mar 12, 2020 at 16:00
1

As indicated in an earlier reply: Magento has multiple caches and you'r probably confusing the built-in cache, with Varnish page caching.

The error you're getting

As the error indicates, you need to make sure the /usr/share/nginx/html/magento2/var/page_cache folder is writeable on your system. You could execute the following command to make this happen: chmod 744 /usr/share/nginx/html/magento2/var/page_cache.

Regarding Varnish

As far as Varnish is concerned: please read the Varnish what's new page to learn about new features and compatibility. Some of the brand new features are now part of the vcl 4.1 syntax and can only be run if you explicitly mention this version in your VCL file.

Magento will probably generate VCL files that have the vcl 4.0 syntax. This makes sure you don't have any incompatibility.

2
  • Am using the VCL files generated by Magento for my installed version of varnish. I think you are right with regards to the wrong cache being configured but I did follow to the letter the instructions in devdocs so either I am incapable of following devdocs instructions properly or devdocs is wrong or there's a bug lingering in Magento that I am bumping in to. Mar 5, 2020 at 9:36
  • Re the var/page_cache the permissions are exactly the same as when I was using built-in cache which worked absolutely fine. I even tried setting it to 777 and it made no difference. The only thing left to do is to debug the code. It is the only thing that I haven't tried. Mar 5, 2020 at 9:38
0

My problem was caused by a change to selinux. The default setting in the image I use from my ISP for selinux used to be switched off by default. That changed in the last week or so to enforced by default.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .