We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
- Home
- Blog
- eCommerce Talk
- How to change Magento 2 configuration using Command Line Interface?
How to change Magento 2 configuration using Command Line Interface?
How to change Magento 2 configuration using Command Line Interface?
Magento offers developers a Command Line Interface (CLI) that allows them to run the default Command-Line functions provided by Magento modules. Here, we will explain how you can change the Magento 2 configuration using the command line.
Before we start, there are some prerequisites to consider while changing the Magento 2 configuration using the command-line interface.
Prerequisites:
- Path to the configuration
- A scope code, which specifies a configuration value for a particular scope.
- Log in to the admin panel using SSH and go to the Magento root directory.
Set configuration values:
To display the configuration setting value, use the below the code:
php bin/magento config:show [--scope[="..."]] [--scope-code[="..."]] path
Now you can set system-specific configuration values in Magento 2.2.0 - 2.2.3, use:
php bin/magento config:set [--scope="..."] [--scope-code="..."] [-l | --lock] path value
You can now set system-specific configuration values in Magento 2.2.4 and higher by using:
php bin/magento config:set [--scope="..."] [--scope-code="..."] [-le | --lock-env] [-lc | --lock-config] path value
Now set sensitive configuration values using:
php bin/magento config:sensitive:set [--scope="..."] [--scope-code="..."] path value
The default configuration path is // or the custom path you configure tag.
In the case of an incorrect path, this command returns an error. The "wrong/config/path" does not exist.
Where
-
Scope- Optional- The scope of the configuration. There are three possible values: default, website, and store. The default will be the default.
Scope-code - Optional - The configuration scope code for the website or store view.
le or-lock-env - Optional - You can either lock the value in the Magento Admin to prevent it from being edited or you can make changes to a setting already locked in the Magento Admin. The command writes the value to the Magento base directory>/app/etc/env.php file.
lc or --lock-config - Optional - You can either lock the value in the Magento Admin to prevent it from being edited or you can make changes to a setting already locked in the Magento Admin. The command writes the value to the Magento base directory>/app/etc/config.php file. If you specify both options, then --lock-config overwrites --lock-env.
path - Required - The path of the configuration.
value - Required - The Configuration value.
Clear cache
To apply the changes, clear the cache config after running your commands:
php bin/magento cache:clean config
To determine if your command is working or not, use the below command:
php bin/magento config:show [--scope[="..."]] [--scope-code[="..."]] path
Or you may check it following the path: Admin >Stores>Configuration
For example:
Display the default Web URL configuration:
php bin/magento config:show --scope="stores" --scope-code="default" web/secure/base_url
Now set the default URL for the default scope:
php bin/magento config:set web/secure/base_url https://store.magespark.com/
Then, you can set the default URL for the base website:
php bin/magento config:set --scope=websites --scope-code=base web/secure/base_url https://www.magespark.com/
Now that you have to set the URL of the store test view:
php bin/magento config:set --scope=stores --scope-code=test web/secure/base_url https://www.magespark.com/
And That’s it!!