Using CLI commands
This example shows how to set shared, system-specific, and sensitive values in your development system, then deploy those values to your production system.
This is done by using a combination of shared configurations, the config.php
file, and Magento CLI command.
This example uses the following configuration settings:
-
Vat Number and Store Name for the shared configuration settings.
These are found under Stores > Settings > Configuration > General > General.
-
Send Emails To for the sensitive configuration value.
This is found under Stores > Settings > Configuration > General > Contacts.
-
Default Email Domain for the system-specific configuration value.
This is found under Stores > Settings > Configuration > Customers > Customer Configuration > Create New Account Options.
You can use the same procedure shown in this example to configure any settings 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
Before you begin
Before you begin, set up file system permissions and ownership as discussed in Prerequisite for your development, build, and production systems.
Assumptions
This topic provides an example of modifying the production system configuration. You can choose different configuration options if you wish.
For the purposes of this example, we assume the following:
- You use Git source control
- The development system is available in a Git remote repository named
mconfig
- Your Git working branch is named
m2.2_deploy
Step 1: Set the configuration in the development system
To set the default locale and weight units in your development system:
- Log in to the Magento Admin.
- Click Stores > Settings > Configuration > General > General.
-
If you have more than one website available, use the Store View list in the upper left corner to switch to a different website as the following figure shows.
- In the right pane, expand Store Information.
- If necessary, clear the Use Default checkbox next to the VAT Number and Store Name fields.
- Enter a number in the field (for example,
12345
). - In the Store Name field, enter a value (like
My Store
). - Click Save Config.
- In the left navigation, under General, click Contacts.
- In the right pane, expand Email Options.
- If necessary, clear the Use Default checkbox next to the Send Emails To field.
- Enter an e-mail address in the field.
- Click Save Config.
-
Use the Store View list to select the Default Config as the following figure shows.
- In the left pane, click Customers > Customer Configuration.
- In the right pane, expand Create New Account Options.
- If necessary, clear the Use system value checkbox next to the Default Email Domain field.
- Enter a domain name in the field.
- Click Save Config.
- If prompted, flush the cache.
Step 2: Update the configuration
Now that you’ve changed the configuration in the Magento Admin, write the shared configuration to a file as using the following steps:
-
Log in to your development system as, or switch to, the Magento file system owner.
-
Enter the following commands in the order shown:
1 2
cd <Magento root dir> php bin/magento app:config:dump
For example, if Magento is installed in
/var/www/html/magento2
, enter:1 2
cd /var/www/html/magento2 php bin/magento app:config:dump
-
If you use Git, enter the following command to confirm that
app/etc/config.php
was updated:1
git status
You should see output similar to the following:
1 2 3 4 5
On branch m2.2_deploy Changed but not updated: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: app/etc/config.php
Do not submit changes to the
generated
,pub/media
, orpub/static
directories to source control. You’ll generate those files on your build system. The development system likely has code, themes, and so on that are not ready for use on the production system. -
Check in your changes to
app/etc/config.php
only to source control.The Git command follows:
1
git add app/etc/config.php && git commit -m "Updated shared configuration" && git push mconfig m2.2_deploy
Note that even though app/etc/env.php
(the system-specific configuration) was updated, don’t check it in to source control.
You will create the same configuration settings on your production system later in this procedure.
Step 3: Update your build system and generate files
Now that you’ve committed your changes to the shared configuration to source control, you can pull those changes into your build system, compile the code, and generate static files.
To update your build system:
- Log in to your build system as, or switch to, the Magento file system owner.
- Change to the build system’s Magento root directory.
-
Pull the changes to
app/etc/config.php
from source control.The Git command follows:
1
git pull mconfig m2.2_deploy
-
Compile code:
1
php bin/magento setup:di:compile
-
After code has been compiled, generate static view files:
1
php bin/magento setup:static-content:deploy -f
-
Check the changes into source control.
The Git command follows:
1
git add -A && git commit -m "Updated files on build system" && git push mconfig m2.2_deploy
Step 4: Update the production system
The last step in the process is to update your production system. You must do it in two parts:
Update the sensitive and system-specific settings
To set the sensitive and system-specific settings using environment variables, you must know the following:
-
Each setting’s scope
If you followed the instructions in Step 1, the scope for Send Emails To is website and the scope for Default Email Domain is global (that is, the Default Config scope).
You need the website code to set the Send Emails To configuration value.
For more information on finding this value, see: Use environment variables to override configuration settings.
-
Configuration paths for the settings used in this example:
Setting name Configuration path Send Emails To contact/email/recipient_email
Default Email Domain customer/create_account/email_domain
For all sensitive and system-specific configuration paths, see: Sensitive and system-specific configuration paths reference.
Set the variables using CLI commands
Use the following CLI commands to set system-specific and sensitive configuration settings:
magento config:set
for system-specific settingsmagento config:sensitive:set
for sensitive settings
To set the system-specific setting Default Email Domain, which is in the default scope, use the following command:
1
bin/magento config:set customer/create_account/email_domain <email domain>
You don’t need to use the scope in the command because it’s the default scope.
To set values for Send Emails To, however, you must know the scope type (website
) and the scope code (which is likely different on every site).
Example:
bin/magento config:sensitive:set contact/email/recipient_email --scope=website --scope-code=<website code> <email address>
Update the shared settings
This section discusses how to pull all the changes you made on your development and build systems to a production environment, which updates the shared configuration settings (Store Name and VAT Number).
To update the production system:
- Log in to your production system as, or switch to, the Magento file system owner.
-
Start maintenance mode:
1
cd <Magento root dir>
1
php bin/magento maintenance:enable
For additional options, such as the ability to set an IP address whitelist, see
magento maintenance:enable
. -
If you use Magento Commerce, stop queue workers. TBD
-
Pull code from source control.
The Git command follows:
1
git pull mconfig m2.2_deploy
-
Update the configuration:
1
php bin/magento app:config:import
-
Clean the cache:
1
php bin/magento cache:clean
-
End maintenance mode:
1
php bin/magento maintenance:disable
Verify configuration settings in the Magento Admin
To verify the configuration settings:
- Log in to your production system’s Magento Admin.
- Click Stores > Settings > Configuration > General > General.
-
Use the Store View list in the upper left corner to switch to a different website.
The shared configuration options you set in the development system are displayed similar to the following.
The Store Name field is editable in the website scope but if you switch to the Default Config scope, it is not editable. This is the result of how you set the options in the development system. The value of VAT Number is not editable in website scope.
- If you haven’t already done so, switch to Default Config scope.
-
In the left navigation, under General, click Contacts.
The Send Emails To field is not editable, as the following figure shows. This is a sensitive setting.
- In the left pane, click Customers > Customer Configuration.
-
In the right pane, expand Create New Account Options.
The value of the Default Email Domain field is displayed as follows. This is a system-specific setting.