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:
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:
- . env.dev development environment
- . env.test test test environment
- . env.beta beta pre release environment
- . env.product on production environment
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.
After configuration, restart nginx. At this time, the system will read the. Env file according to the environment.
See more original articles at:leeon