php bin/magento config:set
Configuration as code (CAC) using bin/magento config:set, now supported since Magento 2.3 allows config between environments backed by version control. This is perhaps a long-awaited feature for large merchants and agencies. Deploying with confidence is now possible for merchants of all sizes.
Practical Examples
Most sane merchants/agencies will be managing config.php via source control so all these suggestions apply. Where developers are adding customisations or commercial extensions, configuration in MAP is often required. The key is baking MAP changes into code so that the expected outcome can be restaged repeatedly before you think about releasing code to production.
config:show
In order to know the configuration path settings, you might need to export the settings you can simply run `bin/magento config:show` to show all options, alternatively you can show just for one website
Show the config for just 1 website
php bin/magento config:show --scope=websites --scope-code=de
Show all the config at base scope
php bin/magento config:show
--lock-config
As of Magento 2.3 you can now execute the following command to bake only that change into config.php to ensure essential settings (that you probably would not wish controlled via MAP) can be set and locked.
php bin/magento config:set --lock-config path value
Here are some examples;
Set the base currency for just 1 website
php bin/magento config:set --scope=websites --scope-code=ie currency/options/base EUR
Set your Google Analytics account code (base scope)
php bin/magento config:set --lock-config google/analytics/account UA-2176794-1
Change catalog prices scoping to website (base scope)
php bin/magento config:set --lock-config catalog/price/scope 1
What the above will do is bake the configuration into the app/etc/config.php file so that you can commit this to source control and take this live. Whats also important is to be able to recreate the scenario and stage the cut-over by recreating your MDOQ instance therefore you can repeatedly validate the process and ensure QA are happy and there are no risks when comparing the alternative of having to manually make changes in MAP at the same time new code is deployed to production.
Once you have executed the function you can Git Push and your `app/etc/config.php` should be identified and taken live. You can then Sync your instance staging the cutover before testing.
TIP: In Magento 2.3+ you the Magento Configuration data (in core_config_data) has a time-stamp for updating data. If you are configuring a new extension or multiple aspects of a new development, and you wish to snapshot all changes made in MAP over a set period you can use the example below to set recent changes into code.
You can run this command in the MySQL Helper for your instance and it will build your bin/magento commands based on the changes you have made in Magento Admin in the last 2 hours.
prefix=$(php -r '$env = include "./app/etc/env.php"; echo $env["db"]["table_prefix"].PHP_EOL;');\
host=$(php -r '$env = include "./app/etc/env.php"; echo $env["db"]["connection"]["default"]["host"].PHP_EOL;');\
user=$(php -r '$env = include "./app/etc/env.php"; echo $env["db"]["connection"]["default"]["username"].PHP_EOL;');\
password=$(php -r '$env = include "./app/etc/env.php"; echo $env["db"]["connection"]["default"]["password"].PHP_EOL;');\
database=$(php -r '$env = include "./app/etc/env.php"; echo $env["db"]["connection"]["default"]["dbname"].PHP_EOL;');\
echo "USE ${database}; select CONCAT('bin/magento config:set --lock-config ',path,' ',value) as command FROM ${prefix}core_config_data WHERE value !='' AND path NOT LIKE '%system_value%' AND updated_at > DATE_SUB(NOW(),INTERVAL 1 HOUR);" | mysql -h ${host} -u ${user} -p${password};
You can then execute the provided commands in the SSH Helper and commit your configuration (app/etc/config.php) to source control