sharing .env files with team members?
Asked Answered
W

2

7

Just starting to dabble using laravel, and they encourage the use of .env files for development.

Its recommended that you do not commit these files into version control, so when a new developer on your team comes to start working on the project, they will not have this file.

The Question

Have I missed something, or are we just expected to effectively email the configured .env files to other developers, for them to drop into their copy of the project so that they can work on it, without finding out the database details etc and adding in theirselves?? Especially when you might be using a vagrant setup with provisioning and the database details are identical, and they'll use the same url. Nothing needs to be configured for them because you're using a controlled environment.

Thanks

Wakashan answered 8/1, 2016 at 19:42 Comment(0)
M
14

.env file do not recommend to add in any VCS instead of that you can create for example .env.example. And set in this file all variable which need your project. Actually, Laravel has this file and you can edit it and add to your VCS. When your team have a new member, he just copy .env.example to .env and set values according to his settings

Edit
You could set command in your composer.jsonfile, after composer install copy .env.example to .env where in your .env.example stores all your setting.

 "post-install-cmd": [
        "php artisan clear-compiled",
        "php -r \"copy('.env.example', '.env');\"",
        "php artisan optimize"
    ],

It give you a flexibility to change values without affecting setting of your team.

Montgolfier answered 8/1, 2016 at 19:54 Comment(7)
Sorry, what do you mean by CVS?Wakashan
but you wouldn't add sensitive data like, mysql passwords inside the .env and then commit to git would you?Wakashan
@Montgolfier it's VCS - Version Control System I believe to describe version control as a whole. CVS is a specific version control systemLilianaliliane
sensitive data stores in .env file, but every environment has a different access(password, ip's) etc... So every environment(production, staging) have different settings. Is it clear for u?Montgolfier
@OwenMelbourne The .env.example file stores the keys of the key value pairs which need to be filled in. Each user fills in the settings which match their personal environment. Production systems should set environment variables properly rather than the file.Lilianaliliane
I think everybody is missing the point of my question, I know what & how .env files work. I'm taking about when a dev in your team starts and you're all using the same vagrant setups etc. so all the details in it are identical, including database user/pass, whats the best way to share these, so the other developer doesn't have to set up the config every time they pull a project e.g. can just do like git clone repo.git && composer install or are you saying that every developer needs to manually fill out this file every time they start on a project, even if their env is identical.Wakashan
@OwenMelbournev if you have absolutely identical .env file and you understand all risks with shared .env just share it with your team. It's not a mandatory rule, it's recommendation. But, If I were I would create .env.example with predefined values and then add a one more command to install process. And the commond would be smth like: git clone repo.git && composer install && php -r "copy('.env.example', '.env');"Montgolfier
M
0

as @xAoc stated you should not include this in version control since it may consist of passwords etc. however if you must do this just remove .env from the .gitignore file and git will not ignore it.

Good Luck.

Muscle answered 8/1, 2016 at 20:37 Comment(1)
as per your updated question do that in your .env.example fileMuscle

© 2022 - 2024 — McMap. All rights reserved.