In this blogpost, I will guide you how to change the Magento 2 configuration from the CLI command. So without wasting much time, lets dive in to the post.
We can set any configuration options from the command line.
- Before installing Magento, one can set the configuration values for the default scope only, which is the only valid scope.
- After installing Magento, You can set the configuration values for any website or store view scope which is quite beneficial.
We use the commands given below to set the Magento 2 configuration:
- bin/magento config:set sets any non-sensitive configuration value by its configuration path.
- bin/magento config:sensitive:set sets any sensitive configuration value by its configuration path.
- bin/magento config:show shows saved configuration values; values of encrypted settings that are displayed as asterisks.
To set a configuration value, you must know at least one of the following:
- The configuration path
- The scope code, to set a configuration value for a particular scope
Set configuration values
- To set system-specific configuration values on Magento 2.2.0 - 2.2.3, use:
$ bin/magento config:set [--scope="..."] [--scope-code="..."] [-l | --lock] path value
- To set system-specific configuration values on Magento 2.2.4 and higher, use:
$ bin/magento config:set [--scope="..."] [--scope-code="..."] [-le | --lock-env] [-lc | --lock-config] path value
- To set sensitive configuration values, use:
$ bin/magento config:sensitive:set [--scope="..."] [--scope-code="..."] path value
- The
config:sensitive:set
command writes sensitive settings to<Magento base directory>/app/etc/env.php
.
- The
--scope : Defines scope of the configuration. Valid values are default, website, or store. The default value is set as default.
--scope-code: Defines scope code of configuration (website code or store view code).
-l or --lock (Version: 2.2.0 - 2.2.3) : Either locks the value so it cannot be edited in the Magento Admin or changes a setting that is already locked in the Magento Admin. The command writes the value to the <Magento base dir>/app/etc/env.php
file.
-le or --lock-eav (Version 2.2.4 and higher) : Either locks the value so it cannot be edited in the Magento Admin or changes a setting that is already locked in the Magento Admin. The command writes the value to the <Magento base dir>/app/etc/env.php
file.
-lc or --lock-config(Version 2.2.4 and higher) : Either locks the value so it cannot be edited in the Magento Admin or changes a setting that is already locked in the Magento Admin. The command writes the value to the <Magento base dir>/app/etc/config.php
file. The --lock-config option overwrites --lock-env if you specify both the options.
Path : Required. The configuration path.
Value : Required. The value of the configuration.
Example:
- Set Sender Email for Sales Representative with default scope:
$ bin/magento config:set trans_email/ident_sales/email sales@aureatelabs.com
- Set the Sender Email for Sales Representative for the base website:
$ bin/magento config:set --scope="website" --scope-code="base" trans_email/ident_sales/email aureate_sales@aureatelabs.com
- Set the Sender Email for Sales Representative for the test store view:
$ bin/magento config:set --scope="stores" --scope-code="default" trans_email/ident_sales/email aureate_sales@aureatelabs.com
Set configuration values that cannot be edited in the Magento Admin
If you have used --lock-eav (version 2.2.4 or higher) or --lock (version 2.2.0-2.2.3) option to set Magento configuration, this command will save the configuration value in <Magento base dir>/app/etc/eav.php
file and will disable the config field for further editing the value in the admin.
$ bin/magento config:set --lock-env --scope=stores --scope-code=default trans_email/ident_sales/email sales@aureatelabs.com
If you have used --lock-config (version 2.2.4 or higher) option to set Magento configuration, this command saves configuration value in <Magento base dir>/app/etc/config.php
file and disables the config field for edit value in the admin.
$ bin/magento config:set --lock-config --scope=stores --scope-code=default web/url/use_store 1
Display the value of configuration settings
$ bin/magento config:show [--scope[="..."]] [--scope-code[="..."]] path
Example:$ bin/magento config:show --scope="stores" --scope-code="default" web/url/use_store
Result :1
Show all saved configuration
$ bin/magento config:show
Result :web/seo/use_rewrites - 1
web/unsecure/base_url - http://127.0.0.1/magento/
web/unsecure/base_static_url -
web/unsecure/base_media_url -
web/secure/base_url - https://127.0.0.1/magento/
web/secure/use_in_frontend - 0
web/secure/use_in_adminhtml - 0
web/secure/base_static_url -
web/secure/base_media_url -
.
.
.
Show all saved configuration for the base website
$ bin/magento config:show --scope="website" --scope-code="base"
Result :web/unsecure/base_url - http://127.0.0.1/magento/
trans_email/ident_sales/email - aureate_sales@aureatelabs.com
.
.
Show Sender Email of Sales Representative configuration for default scope
$ bin/magento config:show trans_email/ident_sales/email
Result :sales@aureatelabs.com
Show Sender Email for Sales Representative configuration for the base website
$ bin/magento config:show --scope="website" --scope-code="base" trans_email/ident_sales/email
If the configuration value is not set for the website, then it will give an error as shown below:Configuration for path: "trans_email/ident_sales/email" doesn't exist
Hope this detailed article served your purpose.
Thanks for your interest.