3

Is there a way to activate the Varnish use using the command line, not the admin interface? In the bin/magento comand line tool there are options for cache but nothing specific for Varnish.

I am building an Ansible script that automatizes the installation and configuration of the M2EE and this step seems that has to be done manually (which I did and works well). I would prefer a command line action than changed direct values in the mySql, but maybe you have other suggestions.

1
  • I believe your question is answered, could you tick the one you like the most? thanks Feb 14, 2020 at 12:12

2 Answers 2

7

Use:

php bin/magento config:set system/full_page_cache/caching_application 2

And follow the same patterns for the other paths, like so:

php bin/magento config:set system/full_page_cache/varnish/access_list localhost
php bin/magento config:set system/full_page_cache/varnish/backend_host localhost
php bin/magento config:set system/full_page_cache/varnish/backend_port 8080
2
  • 1
    is this system/full_page_cache/caching_application value 1 or 2 for varnish? Because in my magento installation, it seems to be 2 for varnish Feb 14, 2020 at 11:55
  • 2
    For reference for others that are not sure : 1 = Built-in Cache and 2 = Varnish Cache. Mar 25, 2021 at 13:38
2

How about adding mysql script.sql with the following contents:

insert into core_config_data(scope,scope_id,path,value) values ('default',0,'system/full_page_cache/caching_application',2), ('default',0,'system/full_page_cache/varnish/access_list','localhost'), ('default',0,'system/full_page_cache/varnish/backend_host','localhost'),('default',0,'system/full_page_cache/varnish/backend_port','8080');

You can change localhost and 8080 to your varnish settings.

2
  • thanks, as I said I would consider this my second option, as I see it "hackish" - because it modifies directly values in the db and overpassing whatever business logic M2 may have when doing the proper activation. Mar 29, 2017 at 11:06
  • 1
    I updated the system/full_page_cache/caching_application value directly inside the database from 2 (Varnish) to 1 (Built-In) and it broke the site. I cleared the cache, restarted Varnish/Web services... nothing worked. I came to this question to assist others. Elzo's advice here is true, there is definitely some M2 business logic additional processing going on when running from command line as other answer showed. Not advised to change DB entry directly Mar 25, 2021 at 13:43

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.