How to Set System Configuration Value Using CLI Command in Magento 2

Magento 2 CMS provides the powerful command-line interface tool that allows the developers to use default commands that perform tasks including installation, modules, indexes management, database backups-updates, compiling LESS, etc.

Moreover, it also provides an excellent feature that allows the developer to set system configuration value using CLI command in Magento 2! You can set Magento 2 default configuration option value as well as third-party extension configuration value from the CLI command.

To do so, you’ll require the value of:

  • The configuration path
  • The scope code
  • Log in to your account using SSH.

The scope code is needed to set a configuration value for a particular scope, and one can find the configuration path from the ‘core_config_data’ table of the database.

To make this explanation more specific, let’s consider an example.

For instance, the admin panel of Magento 2 is not working or opening for any reason. Somehow you have to change the value of the system configuration. In that case, you have to find out a way that can change or set a system configuration value without opening the admin panel!

For such a scenario, use the below method and validate an appropriate value in the CLI command.

Method to Set System Configuration Value Using CLI Command in Magento 2

Pass CLI commands: 

Syntax:

bin/magento config:set [config/path/here] [value]

Example:

bin/magento config:set web/secure/base_url https://domain.com/

In the above command – if the value is locked then there is a chance of facing the error that says:

“The value that you set has already been locked. To change the value, use the –lock-env option.”

In that case, run the command as shown:

bin/magento config:set --lock-env [config/path/here]

Set Website Wise System Configuration Value: 

bin/magento config:set --scope=websites --scope-code=base web/secure/base_url https://domain.com/

Set Store Wise System Configuration Value: 

bin/magento config:set --scope=stores --scope-code=default web/secure/base_url https://domain.com/

That’s it!

Also, do share the post with Magento Community via social media.

Thank you.

Chandresh Chauhan

Article by

Chandresh Chauhan

He has been with Meetanshi for more than three years now as a certified Magento developer. A silent guy whom you can always find solving clients' issues, is an avid reader too.