File based configuration¶
Since Magento 2.2, we can now dump the contents of the configuration table to a PHP array in a file. This new functionality deprecates the config file pool functionality
To dump the configuration, run
This will updated both the
config.php files with the stored config.
Sensitive details are stored in the un-versioned
env.php file with the rest placed in
This will overwrite the contents of both files, any manual changes will be lost!
The contents can be re-imported to the database with
When file based config is in play, any value that is set will override the value stored in the database. Incidentally, you can not edit those fields in the admin any more.
Only configuration files that are set in the files will lock/override the database fields, this means you can have a minimum set of config.
Configuration values set in
env.php override the values set in
There are two types of configuration that are in play.
Environment based config which is specific to the environment that is placed in
General config that is placed in
These values can be moved between each file depending on what is required but bare in mind that any
env.php will override conflicting values in
config.php and the database.
With this in mind, you can consider
config.php to be "shared".
Setting configuration values¶
bin/magento config:set to change configuration values, this will update the database config but not
the file based config.
To update the file based config and lock the config field from editing, use the
This will force the value to be written to
env.php, this can then be manually moved to
to be shared across environments.
Magento uses include and require statements to read the
return values from the files.
As this is just plain PHP this means you can include your own files but beware that this requires
editing the generated files which means they are at risk of being overwritten when a module is enabled or disabled.
Environment based configuration¶
When file based configuration is dumped, it will provide a list of environment variables that can be used. With this you can set sensitive details but be weary that not all values are definable in the env scope, i.e - only a few payment methods.
The output of the dump command closely resembles the structure of the configuration table.
Note, Magento dumps the config in long array syntax.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<?php return [ 'modules' => [ //List of modules (with enabled flag) ], 'scopes' => [ 'websites' => [ //Website scope list ], 'groups' => [ //Group scope list ], 'stores' => [ //Store scope list ], ], 'themes' => [ // List of themes and their configuration values ], 'system' => [ //System level configuration 'default' => [ 'design' => [ 'theme' => [ 'theme_id' => 'frontend/Proswimwear/Proswimwear2018' ] ] ], 'stores' => [ // Store scope overrides of default/system - matches the same strucutre one level deeper 'store_name' => [ // Overrides for store "store_name" ] ], 'websites' => [ // Website scope overrides (like stores) 'website_name' => [ // Overrides for website "website_name" ] ], 'website' =>  ], 'i18n' => [ // Locale translation array( // Local name 'en_US' => array( // Scope 'admin' => array( 'Mage_Catalog::Colour' => 'Colour', 'Mage_Catalog::Swimwear Size' => 'Swimwear Size', 'Mage_Catalog::Country' => 'Country', 'Mage_Catalog::Manufacturer' => 'Manufacturer', 'Mage_Catalog::Flavour' => 'Flavour', 'Mage_Catalog::Shoe Size' => 'Shoe Size', 'Mage_Catalog::Size' => 'Size', ), 'default' => array( 'Mage_Catalog::Colour' => 'Colour', 'Mage_Catalog::Swimwear Size' => 'Swimwear Size', 'Mage_Catalog::Country' => 'Country', 'Mage_Catalog::Flavour' => 'Flavour', 'Mage_Catalog::Shoe Size' => 'Shoe Size', 'Mage_Catalog::Size' => 'Size', ), ), ), ] ];