Get Free Audit

Use Case: Config.php File in Magento 2

Mar 23, 2017

5607 Artsem Miklashevich

Use Case: Config.php File in Magento 2

New projects are usually developed on a separate dedicated web-server which settings may differ from those of a production server. So, to avoid mess-ups when trying to back up the production server it is required either to reassign data in the core_config table or to use a special script. The situation goes worse when there is more than one developer involved in the same project, because each developer may use its own custom set of server configurations.

The solution to the problem is the /etc/config.php file which can help us to set up our data configurations.  Let’s check the file vendor/magento/framework/Config/File/ConfigFilePool.php and private properties of $applicationConfigFiles and $initialConfigFiles


As we see, apart from the main config.php file there are also 2 more files: config.dist.php and config.local.php.  As seen from the properties, the files env.dist.php and env.local.php can help us to reassign data. Let’s assume that we need to reassign the configuration for checkout/cart/delete_quote_after

Add the following code to the config.php file:


Perhaps, it is not the best idea to add new data to the config.php file, instead it is better to use the config.local.php or config.dist.php files for this.

The only thing we need to clarify now is whether it is possible to change the config.php file configuration by creating the same type of settings for config.local.php or config.dist.php files. Let’s check the method \Magento\Framework\App\DeploymentConfig\Reader::loadConfigFile

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor


This is exactly the method where the files become merged. The line


recursively merges env.*.php and config.*.php files. And as we can see the data from env.*.php is replaced by the data from the config.*.php file.

Unfortunately, it is impossible to reassign the data from the config.php with the data from config.*.php files. But generally, we do not need to do that, because config.php contains the information about enabled modules, so, it does not have any information which needs to be modified. The priority of config.local.php is higher than of config.dist.php.

Magento offers convenient ways to reassign file configurations without modifying the database, which lets us arrange flexible development and deploy processes and can also be pretty useful for quality assurance.

UPD. You can back up the current store configurations by the following command:

UPD 2: the file app/etc/config.local.php is not supported by Magento starting from version 2.2.0.

php bin/magento app:config:dump

Consequently, Magento creates config.local.php file and writes the data in it. But please keep in mind that confidential files, such as passwords, will not be included in that file.

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

5 Comments

  1. Hi, Rafael!
    We use it mainly for development tasks. When we take the database from production, config is already set up.

  2. Excellent, thank you for sharing it, could you share how do you use it in your workflow?

  3. Hi,

    Thanks for the remark. We will add this information to the article.

    Regards.

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *