A new console command «bin/magento config:set» has been added to Magento 2.2

Command options:

config:set [--scope="..."] [--scope-code="..."] [-l|--lock] path value

where

  • --scope is the scope of configuration (default, website, or store) (default value is default)
  • --scope-code is the scope code of configuration (website code or store view code)
  • -l|--lock prevents a configuration value from being changed in the Magento Admin
  • path is configuration path (required)
  • value is value of configuration (required)

Set configuration values that can be edited in the Magento Admin

Use magento config:set without -l|-lock to write the value to the database. Values you set this way can be edited in the Magento Admin.

Some examples for setting a store base URL follow:

Example to set the base URL for the default scope:

bin/magento config:set web/unsecure/base_url http://example.com

Example to set the base URL for the base website:

bin/magento config:set --scope=websites --scope-code=base web/unsecure/base_url http://example2.com 

Example to set the base URL for the test store view:

bin/magento config:set --scope=stores --scope-code=test web/unsecure/base_url http://example3.com 

Set configuration values that cannot be edited in the Magento Admin

If you use the -l|--lock option as follows, the configuration value is saved in config.php and the field for editing this value in Admin page is disabled.

bin/magento config:set --lock --scope=stores --scope-code=default web/unsecure/base_url http://example3.com

If you use the -l|--lock option:

  • Configuration values are saved in <Magento base dir>/app/etc/config.php

    Transfer config.php to another system to use the same configuration values there. For example, if you have a testing system, using the same config.php means you don’t have to set the same configuration values again.

  • Configuration values cannot be edited in the Admin.

  • You can use -l|-lock to set configuration values if Magento is not installed. However, you can set values only for the default scope.

In case of wrong configuration path, this command returns an error

The "wrong/config/path" does not exist