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

Before you begin

Before you begin, set up file system permissions and ownership as discussed in Prerequisite for 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:

  1. Log in to the Admin.

  2. Click Stores > Settings > Configuration > General > General.

  3. 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.

    Switch websites

  4. In the right pane, expand Store Information.

  5. If necessary, clear the Use Default checkbox next to the VAT Number and Store Name fields.

  6. Enter a number in the field (for example, 12345).

  7. In the Store Name field, enter a value (like My Store).

  8. Click Save Config.

  9. In the left navigation, under General, click Contacts.

  10. In the right pane, expand Email Options.

  11. If necessary, clear the Use Default checkbox next to the Send Emails To field.

  12. Enter an e-mail address in the field.

  13. Click Save Config.

  14. Use the Store View list to select the Default Config as the following figure shows.

    Switch to the default config

  15. In the left pane, click Customers > Customer Configuration.

  16. In the right pane, expand Create New Account Options.

  17. If necessary, clear the Use system value checkbox next to the Default Email Domain field.

  18. Enter a domain name in the field.

  19. Click Save Config.

  20. If prompted, flush the cache.

Step 2: Update the configuration

Now that you have changed the configuration in the Admin, write the shared configuration to a file as using the following steps:

To update the configuration:

  1. Log in to your development system as, or switch to, the file system owner.

  2. Change to the application root and run the dump command.

    code language-bash
    cd <Magento root dir>
    php bin/magento app:config:dump
    

    For example, if Commerce is installed in /var/www/html/magento2, enter:

    code language-bash
    cd /var/www/html/magento2
    php bin/magento app:config:dump
    
  3. Confirm that app/etc/config.php was updated.

    code language-bash
    git status
    

    Sample response:

    code language-none
    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
    
    note warning
    WARNING
    Do not submit changes to the generated, pub/media, or pub/static directories to source control. You 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.
  4. Check in your changes to app/etc/config.php only to source control.

    code language-bash
    git add app/etc/config.php && git commit -m "Updated shared configuration" && git push mconfig m2.2_deploy
    

Even though app/etc/env.php (the system-specific configuration) was updated, do not 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 have 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 the build system:

  1. Log in to the build system as the file system owner.

  2. Change to the application root directory.

    code language-bash
    cd <Magento root dir>
    
  3. Pull the changes to app/etc/config.php from source control.

    code language-bash
    git pull mconfig m2.2_deploy
    
  4. Compile code.

    code language-bash
    bin/magento setup:di:compile
    
  5. After code has been compiled, generate static view files.

    code language-bash
    bin/magento setup:static-content:deploy -f
    
  6. Check the changes into source control.

    code language-bash
    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
  • Update the shared settings

Update the sensitive and system-specific settings

To set the sensitive and system-specific settings using environment variables, you must know the following:

  • Scope for each setting

    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:

    table 0-row-2 1-row-2 2-row-2
    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 settings
  • magento 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:

bin/magento config:set customer/create_account/email_domain <email domain>

You do not need to use the scope in the command because it is 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:

  1. Log in to the production system as the file system owner.

  2. Change to the application root and enable maintenance mode.

    code language-bash
    cd <Magento root dir>
    
    code language-bash
    bin/magento maintenance:enable
    

    For additional options, such as the ability to set an IP address whitelist, see magento maintenance:enable.

  3. Stop any running queue workers by setting cron_run to false in app/etc/env.php as follows:

    code language-php?start_inline=1
    'cron_consumers_runner' => [
            'cron_run' => false
        ]
    
  4. Update the configuration.

    code language-bash
    bin/magento app:config:import
    
  5. Finally, kill any active consumer processes.

    code language-bash
    kill <PID>
    

    Where PID is the process ID to be killed, for example:

    code language-bash
    kill 1234
    
  6. Pull code from source control.

    code language-bash
    git pull mconfig m2.2_deploy
    
  7. Update the configuration.

    code language-bash
    bin/magento app:config:import
    
  8. Clean the cache.

    code language-bash
    bin/magento cache:clean
    
  9. End maintenance mode.

    code language-bash
    bin/magento maintenance:disable
    

Verify configuration settings in the Admin

To verify the configuration settings:

  1. Log in to your production system’s Admin.

  2. Click Stores > Settings > Configuration > General > General.

  3. Use the Store View list in the upper left corner to switch to a different website.

    The shared configuration options that you set in the development system are displayed similar to the following.

    Check settings in the production system

    note info
    INFO
    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.
  4. If you have not already done so, switch to Default Config scope.

  5. 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.

    Check settings in the production system

  6. In the left pane, click Customers > Customer Configuration.

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

    Check settings in the production system

recommendation-more-help
386822bd-e32c-40a8-81c2-ed90ad1e198c