与团队成员共享 .env 文件?

sharing .env files with team members?

刚开始涉足使用 laravel,他们鼓励使用 .env 文件进行开发。

建议您不要将这些文件提交到版本控制中,这样当您团队中的新开发人员开始处理该项目时,他们将不会有这个文件。

问题

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.

谢谢

.env 文件不建议添加任何 VCS 而不是您可以创建的,例如 .env.example。并在此文件中设置需要您的项目的所有变量。实际上,Laravel 有这个文件,您可以编辑它并添加到您的 VCS。 当你的团队有新成员时,他只需将 .env.example 复制到 .env 并根据他的设置设置值

编辑
您可以在 composer.json 文件中设置命令,在 composer install 将 .env.example 复制到 .env 后 .env.example 存储所有设置。

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

它使您可以灵活地更改值而不影响您的团队设置。

如@xAoc 所述,您不应将其包含在版本控制中,因为它可能包含密码等。但是,如果您必须这样做,只需从 .gitignore 文件中删除 .env 和 git不会理会的。

祝你好运。