T
T
Timur2017-02-09 20:56:05
Yii
Timur, 2017-02-09 20:56:05

Where to store and how to load configs and parameters (main-local, params-local) in Yii2?

Hello. Please tell me who solves the following situation:
There is an application on which the development team is continuously working. The application will be independently deployed on multiple servers (dedik or vps). The codebase is the same. Each production server requires application configuration (database connection and other parameters unique for each server) using main-local and params-local.
If we take yii2-app-advanced as an example, it is supposed to use files for configs and parameters main.php and params.php which are in the repository, and to "overlap" the local parameters of the production server, main-local.php and params-local.php are used, which should not be in the repository (contain confidential data) and data for each server are different.
Question: how to upload main-local.php and params-local.php to the server for the production environment, while keeping them up to date for each server? What if someone on the development team reworks something that requires these files to be updated? How not to miss this moment?
upd: I understand that the main-local.php and params-local.php files intended for production can either be uploaded to the server via ftp / sftp or edited directly on the server, but I don’t like this option, because it is easy to make a mistake, and above all it is not fast. For example, I can update the application via git pull, but I can’t fix the configs manually instantly, I will have to stop the application for a while. While the option with a separate git repository for each production server is spinning in my head, then you can update the application like this

cd /var/www/app; git pull; cd /var/www/app-config; git pull

which will work almost instantly
upd: main-local.php and params-local.php are those used in production

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
matperez, 2017-02-09
@XAKEPEHOK

It can do as advised https://12factor.net/ru/ and load data into the config for the server prod through environment variables. The config will be something like:

'components' => [
  'db' => [
    'dsn' => getenv('db_dsn')
    ...
  ],
  ...
]

And in the dev environment, you can leave the usual config. It's okay that there will be a login and password to the local database.
And keep the *-local.php configs themselves in the same place, they are stored in yii-advanced - in the environments folder.

E
Evgeny Bukharev, 2017-02-09
@evgenybuckharev

Add the logic for compiling the final config with reference to the domain on which the system is running

D
Dmitry, 2017-02-09
@slo_nik

Good evening.
Just remove these files from gitignore and you will be able to upload them to the repository. Although why -local.php on another server if it contains data for a specific server?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question