1 . lumen禁用了生成APP_KEY的命令?php artisan key:generate
?2 . 解禁步骤 :?
? ? ? ? 第一步 :?在 app/Console/Commands下创建文件?KeyGenerateCommand 并添加如下代码
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
class KeyGenerateCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'key:generate';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Set the application key';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$key = $this->generateRandomKey();
file_put_contents(base_path('.env'), preg_replace(
'/^APP_KEY=[\w]*/m',
'APP_KEY='.$key,
file_get_contents(base_path('.env'))
));
$this->info("Application key [$key] set successfully.");
}
/**
* Generate a random key for the application.
*
* @return string
*/
protected function generateRandomKey()
{
return Str::random(32);
}
}
此处注意?str_random(32) 这函数不能用?
? ? ? ? 第二步 :?在app/Console? ??Kernel.php 添加如下代码
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//注入指令
'App\Console\Commands\KeyGenerateCommand',
];
? ? ? ? 第三步 :?执行?php artisan key:generate
? ? ? ? ?至此 32位APP_KEY生成完毕 在 .env文件
????????
|