Environment configuration file layout Solution

Source: Internet
Author: User

Generally, we have a development environment (Dev), a test environment, and a production environment (prod ).

How can I automatically switch the corresponding configuration file according to different environments?

 

This document uses PHP as an example.

 

The simplest way is to ensure that the servers in the three environments can provide identical settings to the program, such as the database address, port, database name, username, and password. However, it is not feasible in an environment where resources are insufficient.

 

First, three corresponding configuration files are required.

For example:

Config. Dev. php

Config. Test. php

Config. Prod. php/config. php

 

Then there is the problem of automatic switching.

In fact, under normal circumstances, the operating environments of these three may be the same and cannot be distinguished simply by different environments. Unless the geeks, such as modifying PHP code, add different environment variable labels to manually compile PHP, so that the runtime environment has differentiated labels and then encapsulates a judgment method. In the case of resource shortage, the operability is also not strong.

The remaining feasible method is soft file connection. * Both nix and windows can create soft file connections. No matter how many configuration files are available in the system, only one file is required during running. Therefore, if the code of the corresponding program is not significantly changed, this is the solution:

Config. Dev. php

Config. Test. php

Config. Prod. php

 

Then, manually create a soft connection config. php In each environment and point to the corresponding file config. XXX. php.

Like a VM, you can directly change config. Prod. php to config. php on the server.

 

PS

There is also an environment for complex and complex resources to be called in large applications. A resource management and scheduling system will be dedicated to naming each resource, such as the MySQL service number, then, in the application environment, call the unified SDK to obtain configuration resources. In this way, we still need to ensure that the test environment and the formal environment cannot be on one machine when the resources are sufficient. In this way, we can judge based on the IP Address requested by the application. If the server is a test server, I will return a configuration data for testing. If this server is a formal environment, the formal configuration will be returned.

Environment configuration file layout Solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.