Laravel5.5 and above multi-environment .env configuration reading

不言
Release: 2023-04-02 16:48:02
Original
5267 people have browsed it

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:
Laravel5.5 and above multi-environment .env configuration reading

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:

  1. .env.dev Development environment

  2. .env.test Test environment

  3. .env.beta beta pre-release environment

  4. .env.producton Production environment

Laravel5.5 and above multi-environment .env configuration reading

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.

Laravel5.5 and above multi-environment .env configuration reading

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!