Thomas Tesla
Thomas Tesla

Reputation: 91

Laravel: Do multiple environments require multiple .env files?

In Laravel 4.x it was possible to have a development and production environment with one configuration file. The framework would detect automatically what should be used according to the host.

With Laravel 5.x it seems I have to take the following approach:

So if I deploy my site, I have to watch that I don't overwrite the .env file on the server with my local version.

Is this correct so far or am I missing something here?

The main goal is to keep sensitive data out of version control and have everything in one place.

Following points and questions about this approach are unclear:

This seems like a step back from the 4.x approach where I could have everything configured and done in one place, no need to have two different files with the same name and watch that I don't mix them up or something. And loading one array in .php is also a lot faster than calling one file multiple times.

Upvotes: 0

Views: 3556

Answers (2)

Marios Fakiolas
Marios Fakiolas

Reputation: 1545

Yes you are right. For 5.x you have to create totally different .env files on any single environment like development, staging, production etc This is included in .gitignore so the git system doesn't care about it. Every manipulation should be made by hand once again when you change environment.

The typical process is to ssh into a remote machine, git clone your project, composer install all dependencies and then create a brand new .env file where you should put all dedicated settings regarding this environment. Your guide is .env.example.

Upvotes: 2

kjellberg
kjellberg

Reputation: 189

If you want to hide a file in UNIX-systems you simply do that by adding a dot to the beginning of the filename. I don't know how it works on Windows systems but the file should be hidden i OS X and Unix systems to prevent people from accidentally copying into another project.

You can only have one .env-file per environment, so you'll have to login to the server and add new .env file manually once.

If you're using GIT and want to prevent it from beeing included just add it into your .gitignore-file

// filename: .gitignore
.env

Upvotes: 0

Related Questions