php Laravel 5 应用密钥
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33700580/
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 5 Application Key
提问by Raham
I am new to Laravel. I just started it tonight. Actually, I have the following code:
我是 Laravel 的新手。我今晚刚开始。实际上,我有以下代码:
'key' => env('APP_KEY', 'SomeRandomString'),
In xampp/htdocs/laravel/blog/config/app.php.
I want to change this key to 32-bit by cmd as:
在xampp/htdocs/laravel/blog/config/app.php 中。
我想通过 cmd 将此密钥更改为 32 位:
xampp\htdocs\laravel/blog>php artisan key:generate
It generates the key but could not replace/update in xampp/htdocs/laravel/blog/config/app.php.
它生成密钥但无法替换/更新xampp/htdocs/laravel/blog/config/app.php。
回答by James
This line in your app.php
, 'key' => env('APP_KEY', 'SomeRandomString'),
, is saying that the key for your application can be found in your .env
file on the line APP_KEY
.
这条线在你的app.php
,'key' => env('APP_KEY', 'SomeRandomString'),
被说为你的应用的关键可以在找到.env
就行了文件APP_KEY
。
Basically it tells Laravel to look for the key in the .env
file first and if there isn't one there then to use 'SomeRandomString'
.
基本上它告诉 Laravel.env
首先在文件中查找密钥,如果没有,则使用'SomeRandomString'
.
When you use the php artisan key:generate
it will generate the new key to your .env
file and not the app.php
file.
当您使用php artisan key:generate
它时,它将为您的.env
文件而不是app.php
文件生成新密钥。
As kotapeter said, your .env
will be inside your root Laravel directory and may be hidden; xampp/htdocs/laravel/blog
正如 kotapeter 所说,你.env
将在你的 Laravel 根目录中并且可能被隐藏;xampp/htdocs/laravel/博客
回答by Peter Kota
You can generate a key
by the following command:
您可以key
通过以下命令生成一个:
php artisan key:generate
The key will be written automatically in your .env
file.
密钥将自动写入您的.env
文件中。
APP_KEY=YOUR_GENERATED_KEY
If you want to see your key
after generation use --show
option
如果您想查看您的key
后代使用--show
选项
php artisan key:generate --show
Note: The .env
is a hidden file in your project folder.
注意:这.env
是项目文件夹中的隐藏文件。
回答by JohnnyAce
Just as another option if you want to print only the key (doesn't write the .env file) you can use:
作为另一个选项,如果您只想打印密钥(不写入 .env 文件),您可以使用:
php artisan key:generate --show
回答by prosti
From the line
从线
'key' => env('APP_KEY', 'SomeRandomString'),
APP_KEY
is a global environment variable that is present inside the .env
file.
APP_KEY
是存在于.env
文件中的全局环境变量。
You can replace the application key if you trigger
如果触发,您可以替换应用程序密钥
php artisan key:generate
command. This will always generate the new key.
命令。这将始终生成新密钥。
The output may be like this:
输出可能是这样的:
Application key [Idgz1PE3zO9iNc0E3oeH3CHDPX9MzZe3] set successfully.
Application key [base64:uynE8re8ybt2wabaBjqMwQvLczKlDSQJHCepqxmGffE=] set successfully.
Base64 encoding should be the default in Laravel 5.4
Base64 编码应该是 Laravel 5.4 中的默认编码
Note that when you first create your Laravel application, key:generate is automatically called.
请注意,当您第一次创建 Laravel 应用程序时,会自动调用 key:generate。
If you change the key be aware that passwords saved with Hash::make()
will no longer be valid.
如果您更改密钥,请注意保存的密码Hash::make()
将不再有效。
回答by ux.engineer
For me the problem was in that I had not yet ran composer update
for this new project/fork. The command failed silently, nothing happened.
对我来说,问题在于我还没有composer update
为这个新项目/fork跑。命令无声无息地失败了,什么也没发生。
After running composer update
it worked.
运行composer update
后就成功了。