11

I have configured Varnish cache in the local Magento 2 environment and It is working fine.

I have added the below lines in the app/etc/env.php file.

'http_cache_hosts' => [
 [
 'host' => '127.0.0.1',
 'port' => '6082'
 ]
]

What is the real purpose of adding this configuration in Magento 2 env.php?

What do these configurations do?

How it affects Magento? Please Help me Out....

Rafael Corrêa Gomes
13.9k15 gold badges92 silver badges190 bronze badges
asked Nov 19, 2019 at 10:30
1

2 Answers 2

8

To make Magento aware of the Varnish servers, add the following section to app/etc/env.php. For Example:

'http_cache_hosts' =>
 array (
 0 =>
 array (
 'host' => 'varnish-0',
 'port' => '80',
 ),
 1 =>
 array (
 'host' => 'varnish-1',
 'port' => '80',
 ),
 ),

In order to ensure the Varnish cache can be cleared, you must also add a node to your env.php to tell Magento how to communicate with Varnish

I hope this will help

answered Nov 19, 2019 at 11:01
3
  • If i don't add these lines in env.php, then Varnish cache won't work as expected in Magento Right ? Commented Nov 19, 2019 at 11:40
  • 1
    It is because If you want to flush the Varnish cache from the Magento backend, you need to add the Varnish server in your Magento config to http-cache-hosts. Commented Nov 19, 2019 at 12:13
  • Related official docs quick access: experienceleague.adobe.com/en/docs/commerce-operations/… Commented Jan 10 at 14:06
2

You can also put Varnish hots using bin/magento:

magento setup:config:set --http-cache-hosts=192.0.2.100,192.0.2.155:6081
answered Jan 16, 2020 at 14:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.