Example using a shared configuration
This example shows how to change the following settings in your development system, update the shared configuration file, config.php
, in your build system, and implement the same settings in your production system:
- Timezone
- Weight unit
These settings are available in the Admin in Stores > Settings > Configuration > General > General.
You can use the same procedure to configure any non-sensitive, non-system-specific settings in the following references:
Before you begin
Before you begin, set up file system permissions and ownership as discussed in Prerequisites 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 timezone and weight units in your development system:
-
Log in to the Admin.
-
Click Stores > Settings > Configuration > General > General.
-
In the right pane, expand Locale Options.
The following figure shows an example.
-
From the Timezone list, click GMT+00:00 (UTC).
-
Clear the Use system value checkbox next to the Weight Unit field.
-
From the Weight Unit list, click kgs.
-
Click Save Config.
-
If prompted, flush the cache.
Step 2: Update the shared configuration
Generate the shared configuration file, app/etc/config.php
, in your development system and transfer it using source control to your build system as discussed in this section.
To update the configuration:
-
Log in to your development system as, or switch to, the file system owner.
-
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
-
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
, orpub/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. -
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
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 in your build system, compile code, and generate static files. The last step is to pull those changes to your production system. As a result, your production system’s configuration will match your development system.
To update the build system:
-
Log in to the build system as the file system owner.
-
Change to the application root directory.
code language-bash cd <Magento root dir>
-
Pull the changes to
app/etc/config.php
from source control.code language-bash git pull mconfig m2.2_deploy
-
Compile code.
code language-bash bin/magento setup:di:compile
-
After code has been compiled, generate static view files.
code language-bash bin/magento setup:static-content:deploy -f
-
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 from source control. This pulls all the changes you made on your development and build systems, which means your production system is completely up-to-date.
To update the production system:
-
Log in to the production system as the file system owner.
-
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
. -
Stop any running queue workers by setting
cron_run
tofalse
inapp/etc/env.php
as follows:code language-php?start_inline=1 'cron_consumers_runner' => [ 'cron_run' => false ]
-
Update the configuration.
code language-bash bin/magento app:config:import
-
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
-
Pull code from source control.
code language-bash git pull mconfig m2.2_deploy
-
Update the configuration.
code language-bash bin/magento app:config:import
-
Clean the cache.
code language-bash bin/magento cache:clean
-
End maintenance mode.
code language-bash bin/magento maintenance:disable
Verify the changes in the Admin
To verify these settings are not editable in the Admin:
-
Log in to the Admin.
-
Click Stores > Settings > Configuration > General > General.
-
In the right pane, expand Locale Options.
The options you just set are displayed as follows:
magento config:set --lock
command.