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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:35:54  来源:igfitidea点击:

Laravel 5 Application Key

phplaravellaravel-5.1

提问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 .envfile 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 .envfile first and if there isn't one there then to use 'SomeRandomString'.

基本上它告诉 Laravel.env首先在文件中查找密钥,如果没有,则使用'SomeRandomString'.

When you use the php artisan key:generateit will generate the new key to your .envfile and not the app.phpfile.

当您使用php artisan key:generate它时,它将为您的.env文件而不是app.php文件生成新密钥。

As kotapeter said, your .envwill 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 keyby the following command:

您可以key通过以下命令生成一个:

php artisan key:generate 

The key will be written automatically in your .envfile.

密钥将自动写入您的.env文件中。

APP_KEY=YOUR_GENERATED_KEY

If you want to see your keyafter generation use --showoption

如果您想查看您的key后代使用--show选项

php artisan key:generate --show

Note: The .envis a hidden file in your project folder.

注意:这.env是项目文件夹中的隐藏文件。

enter image description here

在此处输入图片说明

回答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_KEYis a global environment variable that is present inside the .envfile.

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 updatefor this new project/fork. The command failed silently, nothing happened.

对我来说,问题在于我还没有composer update为这个新项目/fork跑。命令无声无息地失败了,什么也没发生。

After running composer updateit worked.

运行composer update后就成功了。