laravel 如何为laravel生成.env文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29915514/
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 16:59:03  来源:igfitidea点击:

How to generate .env file for laravel?

laravelinstallcomposer-phplaravel-5environment

提问by koalaok

From the documentationI see it's possible to create a laravel project via laravel installer:

文档中我看到可以通过 laravel 安装程序创建一个 laravel 项目:

$laravel new blog

or via composer:

或通过作曲家:

$composer create-project laravel/laravel --prefer-dist

If I try the first way .env file is not created. How can I ask laravel,artisan or composer to create a .env file for me?

如果我尝试第一种方式,则不会创建 .env 文件。我如何让 laravel、artisan 或 composer 为我创建一个 .env 文件?

采纳答案by gan

I had this problem of no .env files showing up in the project.

我遇到了项目中没有显示 .env 文件的问题。

Turns out the IDE I was using (Netbeans, try not to judge) will show certain types of .hidden files but not all.

原来我使用的 IDE(Netbeans,尽量不要判断)会显示某些类型的 .hidden 文件,但不是全部。

After racking my brains for a bit I checked the file system and found the .env + .env.example files / modified them with a text editor.

绞尽脑汁后,我检查了文件系统,找到了 .env + .env.example 文件/用文本编辑器修改了它们。

Leaving this answer for the rare situation someones using a dodgy IDE like myself.

将这个答案留给像我这样使用狡猾 IDE 的人的罕见情况。

回答by Limon Monte

Just tried both ways and in both ways I got generated .envfile:

两种方式都试过了,两种方式我都得到了生成的.env文件:

enter image description here

在此处输入图片说明

Composer should automatically create .env file. In the post-create-project-cmdsection of the composer.jsonyou can find:

Composer 应该自动创建 .env 文件。在 的post-create-project-cmd部分中,composer.json您可以找到:

"post-create-project-cmd": [
  "php -r \"copy('.env.example', '.env');\"",
  "php artisan key:generate"
]

Both ways use the same composer.jsonfile, so there shoudn't be any difference.

两种方式都使用相同的composer.json文件,所以应该没有任何区别。

I suggest you to update laravel/installerto the last version: 1.2 and try again:

我建议您更新laravel/installer最新版本:1.2 并重试:

composer global require "laravel/installer=~1.2"


You can always generate .envfile manually by running:

您始终.env可以通过运行手动生成文件:

cp .env.example .env
php artisan key:generate

回答by Fendi Septiawan

In windows OS, you can open command prompt, change directory to your project directory.
Example,
My project directory

在 Windows 操作系统中,您可以打开命令提示符,将目录更改为您的项目目录。
示例,
我的项目目录

E:\xampp\htdocs\my_project


You can type into your Command prompt like this (hit enter each line):


您可以像这样输入命令提示符(点击输入每一行):

E:

cd xampp\htdocs\my_project

Then you can type,

然后你可以输入,

copy .env.example .env

If you are using Linux, you can type cp, instead of copy

如果您使用的是 Linux,则可以键入cp,而不是copy

回答by Udhav Sarvaiya

If the .enva file is missing, then there is another way to generate a .env file

如果.enva 文件丢失,则还有另一种生成 .env 文件的方法

You can download env.example, rename it to .envand edit it. Just set up correct DB credentials etc.

您可以下载env.example,将其重命名为.env并进行编辑。只需设置正确的数据库凭据等。

Don't forget to When you use the php artisan key:generateit will generate the new key to your .envfile

不要忘记当您使用php artisan key:generate它时,它将为您的.env文件生成新的密钥

回答by Popnoodles

.envfiles are hidden by Netbeans. To show them do this:

.env文件被 Netbeans 隐藏。要向他们展示这样做:

Tools > Options > Miscellaneous > Files

工具 > 选项 > 其他 > 文件

Under Files Ignored be the IDE is Ignored Files Pattern:

在 Files Ignored 下,IDE is Ignored Files Pattern:

The default is

默认是

^(CVS|SCCS|vssver.?\.scc|#.*#|%.*%|_svn)$|~$|^\.(?!(htaccess|git.+|hgignore)$).*$

Add env to the excluded-not-excluded bit

将 env 添加到 exclude-not-excluded 位

^(CVS|SCCS|vssver.?\.scc|#.*#|%.*%|_svn)$|~$|^\.(?!(env|htaccess|git.+|hgignore)$).*$

Files named .envnow show.

命名的文件.env现在显示。

回答by NEOhitokiri

in console (cmd), go to app root path and execute:

在控制台(cmd)中,转到应用程序根路径并执行:

type .env.example > .env

回答by Rodener Dajes

create .env using command!

使用命令创建 .env!

composer run post-root-package-install or sudo composer run post-root-package-install

composer run post-root-package-install 或 sudo composer run post-root-package-install

回答by sitedevcode

This is an old thread, but as it still gets viewed and recently active "26" days ago as of this post, here is a quick solution.

这是一个旧线程,但由于它仍然被查看并且最近在“26”天前活跃于本文,这里是一个快速解决方案。

There is no .envfile initially, you must duplicate .env.exampleas .env.

最初没有.env文件,您必须将.env.example复制为.env

In windows, you can open a command promptaka the CLIand paste the exact code below while inside the root directoryof the project. Must include the (at the start line without space.

windows 中,您可以打开一个命令提示符,也就是CLI,并在项目的根目录中粘贴下面的确切代码。必须在没有空格的起始行包含(

(
echo APP_NAME=Laravel
echo APP_ENV=local
echo APP_KEY=
echo APP_DEBUG=true
echo APP_URL=http://localhost
echo.
echo LOG_CHANNEL=stack
echo.
echo DB_CONNECTION=mysql
echo DB_HOST=127.0.0.1
echo DB_PORT=3306
echo DB_DATABASE=homestead
echo DB_USERNAME=homestead
echo DB_PASSWORD=secret
echo.
echo BROADCAST_DRIVER=log
echo CACHE_DRIVER=file
echo SESSION_DRIVER=file
echo SESSION_LIFETIME=120
echo QUEUE_DRIVER=sync
echo.
echo REDIS_HOST=127.0.0.1
echo REDIS_PASSWORD=null
echo REDIS_PORT=6379
echo.
echo MAIL_DRIVER=smtp
echo MAIL_HOST=smtp.mailtrap.io
echo MAIL_PORT=2525
echo MAIL_USERNAME=null
echo MAIL_PASSWORD=null
echo MAIL_ENCRYPTION=null
echo.
echo PUSHER_APP_ID=
echo PUSHER_APP_KEY=
echo PUSHER_APP_SECRET=
echo PUSHER_APP_CLUSTER=mt1
echo.
echo MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
echo MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
)>".env"

Just press enter to exit the prompt and you should have the .envfile with the default settings created in the same directory you typed above CLIcommand.

只需按 Enter 键退出提示,您应该.env在上面键入CLI命令的同一目录中创建具有默认设置的文件。

Hope this helps.

希望这可以帮助。