Set configuration values
In addition to the command arguments described in this topic, see Common arguments.
Run all Magento CLI commands as the Magento file system owner.
This topic discusses advanced configuration commands you can use to:
- Set any configuration option from the command line
- Optionally lock any configuration option so its value cannot be changed in the Magento Admin
- Change a configuration option that is locked in the Magento Admin
You can use these commands to set the Magento configuration manually or using scripts. You set configuration options using a configuration path, which is a /
-delimited string that uniquely identifies that configuration option. You can find configuration paths in the following references:
- Sensitive and system-specific configuration paths reference
- Payment configuration paths reference
- Other configuration paths reference
- Magento Enterprise B2B Extension configuration paths reference
You can set values at the following times:
-
Before you install Magento, you can set configuration values for the default scope only.
That’s because before you install Magento, the default scope is the only valid scope.
-
After you install Magento, you can set configuration values for any website or store view scope.
Use the following commands:
bin/magento config:set
sets any non-sensitive configuration value by its configuration pathbin/magento config:sensitive:set
sets any sensitive configuration value by its configuration pathbin/magento config:show
shows saved configuration values; values of encrypted settings are displayed as asterisks
Prerequisites
To set a configuration value, you must know at least one of the following:
- The configuration path
-
To set a configuration value for a particular scope, you must know the scope code.
To set a configuration value for the default scope, you don’t need to do anything.
Find the configuration path
See the following references:
- Sensitive and system-specific configuration paths reference
- Payment configuration paths reference
- Other configuration paths reference
- Magento Enterprise B2B Extension configuration paths reference
Find the scope code
You can find the scope code either in the Magento database or in the Magento Admin. See one of the following sections for more information.
Find the scope code in the Admin
- Log in to the Admin as a user who can view websites and store views.
- Click Stores > Settings > All Stores.
-
In the right pane, click the name of the website or store view to see its code.
The following figure shows a sample website code.
- Continue with Set configuration values.
Find the scope code in the database
Scope codes for websites and store views are stored in the Magento database in the store_website
and store
tables, respectively.
To find the values in the database:
-
Connect to the Magento database.
mysql -u <magento database user name> -p
-
Enter the following commands:
use <magento database name>; SELECT * FROM store; SELECT * FROM store_website;
A sample result follows:
[mysql]> SELECT * FROM store_website; +------------+-------+--------------+------------+------------------+------------+ | website_id | code | name | sort_order | default_group_id | is_default | +------------+-------+--------------+------------+------------------+------------+ | 0 | admin | Admin | 0 | 0 | 0 | | 1 | base | Main Website | 0 | 1 | 1 | | 2 | test1 | Test Website | 0 | 3 | 0 | +------------+-------+--------------+------------+------------------+------------+
Use the value in the
code
column. -
Continue with the next section.
Set configuration values
To set system-specific configuration values, use:
bin/magento config:set [--scope="..."] [--scope-code="..."] [-l|--lock] path value
where
--scope
is the scope of configuration (default
,website
, orstore
). The default value isdefault
.--scope-code
is the scope code of configuration (website code or store view code)-
-l|--lock
enables you to:- Lock the value so it cannot be edited in the Magento Admin
- Change a setting that is already locked in the Magento Admin
path
is configuration path (required)value
is value of configuration (required)
To set sensitive configuration values, use:
bin/magento config:sensitive:set [--scope="..."] [--scope-code="..."] path value
See one of the following sections for more information:
- Set configuration values that can be edited in the Magento Admin
- Set configuration values that cannot be edited in the Magento Admin
Set configuration values that can be edited in the Magento Admin
Use bin/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 env.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/env.php
Transfer
env.php
to another system to use the same configuration values there. For example, if you have a testing system, using the sameenv.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.
If you enter an incorrect configuration path, this command returns an error
The "wrong/config/path" does not exist
If you use the --lock
option to set or change a value, you must use the bin/magento app:config:import
command to import the setting before you access the Admin or storefront.
Display the value of configuration settings
Command options:
bin/magento config:show [--scope[="..."]] [--scope-code[="..."]] path
where
--scope
is the scope of configuration (default, website, store). The default value isdefault
--scope-code
is the scope code of configuration (website code or store view code)path
is the configuration path in format first_part/second_part/third_part/etc (required)
The bin/magento config:show
command displays the values of any encrypted values as a series of asterisks: ******
.
Examples
Show all saved configurations:
bin/magento config:show
Result:
web/unsecure/base_url - http://example.com/ general/region/display_all - 1 general/region/state_required - AT,BR,CA,CH,EE,ES,FI,LT,LV,RO,US catalog/category/root_id - 2 analytics/subscription/enabled - 1
Show all saved configurations for the base
website:
bin/magento config:show --scope=websites --scope-code=base
Result:
web/unsecure/base_url - http://example-for-website.com/ general/region/state_required - AT,BR,CA
Show the base URL for the default scope:
bin/magento config:show web/unsecure/base_url
Result:
web/unsecure/base_url - http://example.com/
Show the base URL for the base
website:
bin/magento config:show --scope=websites --scope-code=base web/unsecure/base_url
Result:
web/unsecure/base_url - http://example-for-website.com/
Show the base URL for the default
store:
bin/magento config:show --scope=stores --scope-code=default web/unsecure/base_url
Result:
web/unsecure/base_url - http://example-for-store.com/