How to activate and setup full page caching using Varnish from command line
-
07-10-2020 - |
Question
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.
Solution
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
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange