流明微框架=> PHP的工匠键:生成 [英] Lumen Micro Framework => php artisan key:generate

查看:87
本文介绍了流明微框架=> PHP的工匠键:生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试用PHP micro Framework Lumen(来自Laravel).

I'm trying out the PHP micro Framework Lumen (from Laravel).

我的第一步是研究.env.example文件并对其进行复制以包含我的.env文件.就像Laravel中一样,有一个变量APP_KEY.现在,我尝试了简单的命令php artisan key:generate来获取新密钥,但是遇到了以下错误消息:

One of my first steps was to look into the .env.example file and make a copy of it to have my .env file. There is a variable APP_KEY just like there is in Laravel. Now I tried out the simple command php artisan key:generate to get my new key But I ran into the following error message:

[InvalidArgumentException] 在键"中未定义任何命令 命名空间.

[InvalidArgumentException] There are no commands defined in the "key" namespace.

有人知道我如何为流明生成密钥吗?

Does some one know how I can generate keys for Lumen?

使用解决方案更新

因此,我找到了我最喜欢的解决方案.在命令行(Linux)上,我运行php -r "echo md5(uniqid()).\"\n\";",这给了我7142720170cef01171fd4af26ef17c93这样的东西.

So I found my favorite solution for this problem. On the command line (Linux) I run php -r "echo md5(uniqid()).\"\n\";" what gives me something like this 7142720170cef01171fd4af26ef17c93.

如果要更频繁地使用Lumen,则可能需要在.bashrc中创建别名,该别名位于主目录/home/USERNAME中.为此,可以使用nano ~/.bashrcvi ~/.bashrc打开文件,并在文件末尾alias phpkey='php -r "echo md5(uniqid()).\"\n\";"'中复制以下别名.现在,您可以使用命令phpkey,该命令将为您提供32个字符长的随机字符串:)

If you are going to use Lumen more often, you may want to create an alias in your .bashrc, which is located in your home directory /home/USERNAME. To do so, you can open the file with nano ~/.bashrc or vi ~/.bashrc and copy the following alias at the end of the file, alias phpkey='php -r "echo md5(uniqid()).\"\n\";"'. Now you can use the command phpkey which will give you a 32 character long random string :)

推荐答案

Laravel命令非常简单.它只是生成一个随机的32个字符长的字符串.您可以在流明做同样的事情.只是暂时添加一条这样的路线:

The Laravel command is fairly simple. It just generates a random 32 character long string. You can do the same in Lumen. Just temporarily add a route like this:

$router->get('/key', function() {
    return \Illuminate\Support\Str::random(32);
});

然后在浏览器中转到/key,然后将密钥复制粘贴到您的.env文件中.
然后删除路由.

Then go to /key in your browser and copy paste the key into your .env file.
Afterwards remove the route.

很显然,您也可以在线使用一些随机字符串生成器. 喜欢这个

Obviously you could also use some random string generator online. Like this one

这篇关于流明微框架=> PHP的工匠键:生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆