15

First of all it is maybe an already answered question but I did not find anything about that subject.

It is not an issue but a question about the best way to manage the file config.php in Magento 2.
Actually our config.php is not versioned (by default in M2 .gitignore file) so it is not in our repository. The problem is when someone install the project he doesn't have this file but he already have the database so he can't run bin/magento setup:install ... to generate the file.
We are aware that the bin/magento setup:upgrade add non declared modules to config.php but only if the file exists and the bin/magento module:enable can add modules but we would like to avoid to launch that every time we deploy or install the project.

My question(s) :
- Do we have to remove config.php from .gitignore and version it ?
- Do we have to add it the first time in the repository and let it in the .gitignore after ?
- What is the best way to manage this file ?

15

First of all, very good question.
But...I don't agree with this:

The problem is when someone install the project he doesn't have this file but he already have the database so he can't run bin/magento setup:install ...

I would say that when you install the project, if you already have the database, you should take the config.php file also from the same place you got the database.
This way you don't have to run setup:install and you have everything as it should be.

I would not recommend versioning this file because of the following scenario.

  • You add a new module on the dev env.
  • You run setup:upgrade so the module appears not in config.php
  • You commit your code and deploy it on an other env.
  • Your other env instance thinks your new module is already installed and you get an error.

So I guess the best solution (IMO) would be to just not version it and do this depending on your case:

  • You clone the project and the database somewhere else, you should clone the config.php file also (along with others like pub/media) so you won't have outdated data.
  • You clone only the files in the repo and start on a clean slate, don't copy config.php, just run the installer that will create that for you.
  • I had not thought of this solution, it does not appear to be the most practical, but you are right actually it is one that seems the most logical. We will test this way. If that does not bother you I will wait the end of the day to accept your answer maybe other advice might be given. Thank you anyway ! – Matthéo Geoffray Aug 5 '16 at 8:53
  • I tried removing config.php from the repo and added it to .gitignore. Another environment failed to generated a new config.php file when it did not exist (in developer mode). – dchayka Oct 23 '17 at 20:41
  • what do you mean by "failed"? did you try to install it on a different env? – Marius Oct 23 '17 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.