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:

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 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 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:

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

To find the scope code in the Admin:
  1. Log in to the Admin as a user who can view websites and store views.
  2. Click Stores > Settings > All Stores.
  3. 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.

    Get a website or store view code from the Admin

  4. Continue with Set configuration values.

Find the scope code in the database

To 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:

  1. Connect to the Magento database.

    1
    
    mysql -u <magento database username> -p
    
  2. Enter the following commands:

    1
    
    use <magento database name>;
    
    1
    
    SELECT * FROM store;
    
    1
    
    SELECT * FROM store_website;
    

    A sample result follows:

    1
    2
    3
    4
    5
    6
    7
    8
    
    [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.

  3. Continue with the next section.

Set configuration values

To set system-specific configuration values, use:

1
bin/magento config:set [--scope="..."] [--scope-code="..."] [-le | --lock-env] [-lc | --lock-config] path value

To set sensitive configuration values, use:

1
bin/magento config:sensitive:set [--scope="..."] [--scope-code="..."] path value

The following table describes the set command parameters:

Parameter Description
--scope The scope of the configuration. The possible values are default, website, or store. The default is default.
--scope-code The scope code of configuration (website code or store view code)
-le or --lock-env 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 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 options.
path Required. The configuration path
value Required. The value of the configuration
  • As of Magento 2.2.4, the --lock-env and --lock-config options replace the --lock option.
  • If you use the --lock-env or --lock-config 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.

If you enter an incorrect configuration path, this command returns an error

1
The "wrong/config/path" does not exist

See one of the following sections for more information:

Set configuration values that can be edited in the Magento Admin

Use bin/magento config:set without --lock-env or --lock-config 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:

Set the base URL for the default scope:

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

Set the base URL for the base website:

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

Set the base URL for the test store view:

1
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 --lock-env option as follows, the command saves the configuration value in <Magento base dir>/app/etc/env.php and disables the field for editing this value in Admin.

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

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

The env.php file is system specific. You should not transfer it to another system. You can use it to overwrite configuration values from the database. For example, you can take a database dump from another system and overwrite the base_url and other values so you don’t have to modify the database.

If you use the --lock-config option as follows, the configuration value is saved in <Magento base dir>/app/etc/config.php. The field for editing this value in Admin page is disabled.

1
bin/magento config:set --lock-config --scope=stores --scope-code=default web/url/use_store 1

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

You can 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.

Display the value of configuration settings

Command options:

1
bin/magento config:show [--scope[="..."]] [--scope-code[="..."]] path

where

  • --scope is the scope of configuration (default, website, store). The default value is default
  • --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:

1
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:

1
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:

1
bin/magento config:show web/unsecure/base_url

Result:

web/unsecure/base_url - http://example.com/

Show the base URL for the base website:

1
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:

1
bin/magento config:show --scope=stores --scope-code=default web/unsecure/base_url

Result:

web/unsecure/base_url - http://example-for-store.com/

Related topic

Deployment general overview