Identify database server (approval and production) in two different environments

Asked

Viewed 240 times

1

As in most cases, I have two environments: approval and production, both for the server and for the database.

I would like to know how to use the same address (host) of the database in the application settings (in PHP) where, when running in type approval environment, the host points to the type approval database, when in production, the host pointed to the production database, thus avoiding adjusting the database host whenever the server was promoted to production (deploy).

2 answers

0

The host is even simple, you could point in your /etc/hosts to different addresses or use an "internal" DNS that solves for different names. But in addition to the hosts, it has the authentication credentials and other environment variables, more recommended that the host be configurable, as well as the rest.

0

If your goal is not to have to change the code between approval and production, my suggestion is to follow the guidelines of configuration in 12 Factor App.

Make your application read the host name (and port, bank name, login, password) of an environment variable. In each environment you configure the variables as you want and your code does not need to be touched: the same that ran in homologation will run in production.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.