What are the sources of Magento configuration, and which priorities have different sources of Magento configuration?
All system configurations are set during deployment according to the following override scheme:
- If an environment variable exists, use the custom configuration and ignore the default configuration.
- If an environment variable does not exist, use the configuration from a
MAGENTO_CLOUD_RELATIONSHIPS
name-value pair in the.magento.app.yaml
file. Ignore the default configuration. - If an environment variable does not exist and
MAGENTO_CLOUD_RELATIONSHIPS
does not contain a name-value pair, remove all customized configuration and use the values from the default configuration.
The general format of system settings variable names follows:<SCOPE>__<SYSTEM__VARIABLE__NAME>
<SCOPE>
can be either:
- Global scope (that is, the global setting for all scopes)
Global scope variables have the following format:
CONFIG__DEFAULT__<SYSTEM__VARIABLE__NAME>
- A specific scope (that is, the setting affects only a specified store view or website)
Store view scope variables, for example, have the following format:
CONFIG__STORES__ <STORE_VIEW_CODE>__<SYSTEM__VARIABLE__NAME>
<SYSTEM__VARIABLE__NAME>
is derived from a configuration setting’s configuration path, which is a / delimited string that uniquely identifies a particular setting.
Replace each / character in the configuration path with two underscore characters to create the system variable.
Example:
variables:
env:
CONFIG__DEFAULT__PAYPAL_ONBOARDING__MIDDLEMAN_DOMAIN: 'payment-broker.magento.com'
CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL: 'Magento_Enterprise_Cloud_BT'
CONFIG__STORES__DEFAULT__PAYPAL__NOTATION_CODE: 'Magento_Enterprise_Cloud'
Use environment variables to override configuration settings
Any data that exports to the file becomes locked. The corresponding field in the Magento Admin becomes read-only. This ensures consistent configurations as you push the file across all environments. And every time you run this command, any new configurations are appended to your config.php file. If you need to modify or delete an existing configuration, you must edit the file manually.
update app/etc/config.php
file, commit and push to Git.
Example of managing system-specific settings
- Install module:
composer require <component-name>:<version>
When adding the module to composer.json, the file app/etc/config.php will also be updated. This file includes a list of installed modules, themes, and language packages, shared configuration settings.
- Verify the extension:
php bin/magento module:status
- Commit and push changes:
git add -A git commit -m "<message>" git push magento <environment ID>
Install, manage, and upgrade extensions
Enable a module. This command updates the config.php file with the enabled status of the module.
php bin/magento module:enable <module name>
Disable a module. This command updates the config.php file with the disable status of the module.
php bin/magento module:disable <module name>
Commit app/etc/config.php
file and push to Git.
Know how to setup multisite configuration: Adding and configuring new websites in Magento; Nginx configuration through the .magento.app.yaml for multisite setup; how to route websites through the magento-vars.php
- Configure routes in
.magento/routes.yaml
For Pro, you must create a Support ticket to set up routes in the Staging or Production environment.
"http://{default}/":
type: upstream
upstream: "mymagento:php"
"https://{default}/":
type: upstream
upstream: "mymagento:php"
"http://*.{default}/":
type: upstream
upstream: "mymagento:php"
"https://*.{default}/":
type: upstream
upstream: "mymagento:php"
-
Set up websites, stores, and store views Set up multiple websites, stores, and store views in the Admin
-
Modify the
magento-vars.php
file
Instead of configuring an NGINX virtual host, pass the MAGE_RUN_CODE and MAGE_RUN_TYPE variables using the magento-vars.php file located in your project root directory.
<?php
// default magento-vars.php from magento cloud repo
// enable, adjust and copy this code for each store you run
// Store #0, default one
//if (isHttpHost("example.com")) {
// $_SERVER["MAGE_RUN_CODE"] = "default";
// $_SERVER["MAGE_RUN_TYPE"] = "store"; // website
//}
function isHttpHost($host)
{
if (!isset($_SERVER['HTTP_HOST'])) {
return false;
}
return strpos(str_replace('---', '.', $_SERVER['HTTP_HOST']), $host) === 0;
}
Example:
<?php
// enable, adjust and copy this code for each store you run
// Store #0, default one
function isHttpHost($host)
{
if (!isset($_SERVER['HTTP_HOST'])) {
return false;
}
return $_SERVER['HTTP_HOST'] === $host;
}
if (isHttpHost("french.branch-sbg7pPa-f3dueAiM03tpy.us.magentosite.cloud"))
{
$_SERVER["MAGE_RUN_CODE"] = "french";
$_SERVER["MAGE_RUN_TYPE"] = "website";
}
After deployment, open your site base URL in a web browser.
Use the format: http://. For example, http://french.master-name-projectID.us.magentosite.cloud/
Set up multiple websites or stores
Cloud variables ADMIN variables
example:
- ADMIN_USERNAME
- ADMIN_EMAIL
- ADMIN_PASSWORD
- ADMIN_LOCALE
- ADMIN_URL
- CRON_CONSUMERS_RUNNER
- CRYPT_KEY
- UPDATE_URLS
Note: it's possible to override values from .magento.env.yaml
from deploy stage.
see:
- Config\Stage\Deploy::get
- Config\Stage\Deploy\MergedConfig::get
- Config\Stage\Deploy\EnvironmentConfig::getAll
Variables from MAGENTO_CLOUD_VARIABLES
(base64 encoded json) env variable (common variable in admin panel)
Environment variables have prefix env:
in admin panel
When attempting to use environment variables to override configuration settings using the Project Web Interface, you must prepend the variable name with env: as in the following example.
Project-specific variables To set the same value for all environments in your project, use the magento-cloud project:variable:set command. These variables are available at build and runtime in all environments.
Environment-specific variables To set a unique value for a specific environment, use the magento-cloud variable:set command. These variables are available at runtime and are inherited by child environments. You should specify the environment in your command using the -e option.
Documentation: