Skip to content

Config

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

Changelog Blog Post explaining in depth

To dump the configuration, run bin/magento app:config:dump This will updated both the env.php and config.php files with the stored config. Sensitive details are stored in the un-versioned env.php file with the rest placed in config.php.

Note

This will overwrite the contents of both files, any manual changes will be lost!

The contents can be re-imported to the database with bin/magento app:config:import

Configuration precedence

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

Config Types

There are two types of configuration that are in play. Environment based config which is specific to the environment that is placed in env.php. General config that is placed in config.php.

These values can be moved between each file depending on what is required but bare in mind that any value in 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

Use 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 --lock flag. This will force the value to be written to env.php, this can then be manually moved to config.php to be shared across environments.

Configuration split

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.

Structure

The output of the dump command closely resembles the structure of the configuration table.

Note, Magento dumps the config in long array syntax.

<?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',
                        ),
                ),
        ),   
    ]
];