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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:30:00  来源:igfitidea点击:

Laravel project missing .env file

laravelgithubgit-pull

提问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 .envand edit it. Just set up correct DB credentials, etc.

您可以从 Laravel 源代码下载标准的env.example文件,将其重命名为.env并进行编辑。只需设置正确的数据库凭据等。

Don't forget to run the php artisan key:generatecommand which will generate an application (encryption) key and add it to the .envfile.

不要忘记运行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

  1. Duplicate the Readme.md file in your project using your IDE
  2. Edit the duplicate to .env
  3. Copy content from .env.example
  4. Paste it in your .env file
  5. Run php artisan key:generate
  1. 使用 IDE 复制项目中的 Readme.md 文件
  2. 将副本编辑为 .env
  3. .env.example复制内容
  4. 将其粘贴到您的 .env 文件中
  5. php artisan key:generate

回答by Tim

After running composer create-project --prefer-dist laravel/laravelnot 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

.gitignoreis important because it prevents the newly created .envfrom being commited.

.gitignore很重要,因为它可以防止新创建.env的被提交。