Home >Backend Development >PHP Tutorial >Laravel5.5 and above multi-environment .env configuration reading
This article mainly introduces the multi-environment .env configuration reading of Laravel5.5 and above. It has a certain reference value. Now I share it with you. Friends in need can refer to it
laravel default When engineering a .env file, how to automatically distinguish and read different .env files in multiple running environments? In fact, laravel itself has implemented multi-environment reading of .env. Those tutorials on the Internet all require adding code to identify or explain it unclearly. Laravel implements reading different .env logic in the bottom layer of the framework of version 5.5. . Please see the screenshot:
So how do we use this feature? It's actually very simple. We have 4 environments (dev environment, test environment, beta environment, production environment).
We only need to create four files in the project root directory. You can notice that different environments have different environment keywords, which are:
.env.dev Development environment
.env.test Test environment
.env.beta beta pre-release environment
.env.producton Production environment
After creation, configure relevant configuration data in different environments.
Here comes the point. This is also the most important asynchronous. How to tell laravel to read the .env configuration file of the specified environment. In fact, it only takes two steps. Add a line to the PHP configuration parameter section of the nginx configuration in your specified operating environment:
fastcgi_param APP_ENV test; // Fill in the corresponding environment keywords according to the environment.
After configuration, restart nginx. At this time, the system will read the .env file according to the environment.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Advantages of using Laravel service container
##Solution to the problem that the table is empty when executing the table migration command in Laravel5.5
The above is the detailed content of Laravel5.5 and above multi-environment .env configuration reading. For more information, please follow other related articles on the PHP Chinese website!