Laravel 项目缺少 .env 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39053657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel project missing .env file
提问by Yohannes Taye
I'm new to laravel and i recently pulled a project from git-hub and it wouldn't run because it's missing the .env file i tried composer install but that didn't work. Is there any other way to generate the .env file?
我是 laravel 的新手,我最近从 git-hub 中提取了一个项目,但它无法运行,因为它缺少 .env 文件,我尝试过 composer install 但这没有用。有没有其他方法可以生成 .env 文件?
回答by Alexey Mezenin
You can download the standard env.examplefile from the Laravel source code, rename it to .env
and edit it. Just set up correct DB credentials, etc.
您可以从 Laravel 源代码下载标准的env.example文件,将其重命名为.env
并进行编辑。只需设置正确的数据库凭据等。
Don't forget to run the php artisan key:generate
command which will generate an application (encryption) key and add it to the .env
file.
不要忘记运行php artisan key:generate
将生成应用程序(加密)密钥并将其添加到.env
文件的命令。
回答by derdida
Just open an editor and create an .env file. Its a simple Text File.
只需打开一个编辑器并创建一个 .env 文件。它是一个简单的文本文件。
And its ignored by git, because it contains sensitive data.
它被 git 忽略,因为它包含敏感数据。
Edit: Normally there should be an .env.example file it the folder (which is not ignored by git by default), you can rename it to .env
编辑:通常应该有一个 .env.example 文件夹(默认情况下不会被 git 忽略),您可以将其重命名为 .env
回答by Solomon Darku
- Duplicate the Readme.md file in your project using your IDE
- Edit the duplicate to .env
- Copy content from .env.example
- Paste it in your .env file
- Run
php artisan key:generate
- 使用 IDE 复制项目中的 Readme.md 文件
- 将副本编辑为 .env
- 从.env.example复制内容
- 将其粘贴到您的 .env 文件中
- 跑
php artisan key:generate
回答by Tim
After running composer create-project --prefer-dist laravel/laravel
not all files are installed, including .env.example
.
运行后composer create-project --prefer-dist laravel/laravel
并非所有文件都被安装,包括.env.example
.
curl https://raw.githubusercontent.com/laravel/laravel/master/.env.example > .env
php artisan key:generate
curl https://raw.githubusercontent.com/laravel/laravel/master/.gitignore > .gitignore
curl https://raw.githubusercontent.com/laravel/laravel/master/.gitattributes > .gitattributes
curl https://raw.githubusercontent.com/laravel/laravel/master/.editorconfig > .editorconfig
.gitignore
is important because it prevents the newly created .env
from being commited.
.gitignore
很重要,因为它可以防止新创建.env
的被提交。