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
How to generate .env file for laravel?
提问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 .env
file:
两种方式都试过了,两种方式我都得到了生成的.env
文件:
Composer should automatically create .env file. In the post-create-project-cmd
section of the composer.json
you 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.json
file, so there shoudn't be any difference.
两种方式都使用相同的composer.json
文件,所以应该没有任何区别。
I suggest you to update laravel/installer
to the last version: 1.2 and try again:
我建议您更新laravel/installer
到最新版本:1.2 并重试:
composer global require "laravel/installer=~1.2"
You can always generate .env
file 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 .env
a file is missing, then there is another way to generate a .env file
如果.env
a 文件丢失,则还有另一种生成 .env 文件的方法
You can download env.example, rename it to .env
and edit it. Just set up correct DB credentials etc.
您可以下载env.example,将其重命名为.env
并进行编辑。只需设置正确的数据库凭据等。
Don't forget to When you use the php artisan key:generate
it will generate the new key to your .env
file
不要忘记当您使用php artisan key:generate
它时,它将为您的.env
文件生成新的密钥
回答by Popnoodles
.env
files 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 .env
now 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 .env
file with the default settings created in the same directory you typed above CLI
command.
只需按 Enter 键退出提示,您应该.env
在上面键入CLI
命令的同一目录中创建具有默认设置的文件。
Hope this helps.
希望这可以帮助。