[original] multi environment. Env configuration reading of laravel 5.5 and above

Time:2021-9-1

By default, the laravel project has an. Env file. How to automatically distinguish and read different. Env files in multiple running environments? In fact, laravel itself has implemented multi environment reading. Env. Those online tutorials need to add code to identify or speak unclear. Laravel implements different. Env logic in the bottom layer of the 5.5 framework. Please see the screenshot:
[original] multi environment. Env configuration reading of laravel 5.5 and above

So how do we use this feature? In fact, it’s very simple. We have four environments (DEV environment, test environment, beta environment and production environment).

We only need to create four files in the project root directory. We can notice that different environments have different environment keywords, namely:

  1. . env.dev development environment
  2. . env.test test test environment
  3. . env.beta beta pre release environment
  4. . env.product on production environment

[original] multi environment. Env configuration reading of laravel 5.5 and above

After creation, configure relevant configuration data in different environments.

Here’s the point. This is also the most important asynchronous. How do you tell laravel to read the. Env configuration file of the specified environment. In fact, it only needs two steps. Add a line to the PHP configuration parameter section of nginx configuration in your specified running environment:

fastcgi_ param APP_ ENV test; // Fill in the corresponding environment keywords according to different environments.

[original] multi environment. Env configuration reading of laravel 5.5 and above

After configuration, restart nginx. At this time, the system will read the. Env file according to the environment.

See more original articles at:leeon