"php artisan key:generate"给出“未指定应用程序加密密钥".错误 [英] "php artisan key:generate" gives a "No application encryption key has been specified." error

查看:657
本文介绍了"php artisan key:generate"给出“未指定应用程序加密密钥".错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个克隆的laravel应用程序,但是当我尝试通过php artisan key:generate生成APP_KEY时,它给了我一个错误:

I have a cloned laravel application but when I try to generate a APP_KEY via php artisan key:generate it gives me an error:

In EncryptionServiceProvider.php line 42:
No application encryption key has been specified.

这很明显,因为这正是我要创建的内容.有人知道如何调试此命令吗?

Which is obvious because that is exactly what I'm trying to create. Does anybody know how to debug this command?

更新:对此文章进行了修复 laravel 4:密钥不是由工匠生成的

update: Kind of fixed it with this post laravel 4: key not being generated with artisan

如果我在.env文件中填写APP_KEY,则php artisan key:generate起作用.但是通过laravel new删除了APP_KEY的新创建的应用程序可以运行php artisan key:generate而没有任何问题.

If I fill APP_KEY in my .env file php artisan key:generate works. But a newly created app via laravel new with a deleted APP_KEY can run php artisan key:generate without issue for some reason.

出于某种原因,php artisan key:generate认为不需要时需要一个app_key.它也不会执行任何其他命令,它们都将显示错误未指定应用程序加密密钥".

For some reason php artisan key:generate thinks it needs a app_key when it doesn't. It won't do any other commands either, they all error "No application encryption key has been specified."

推荐答案

php artisan key:generate需要一个现有的密钥才能工作.用32个字符填充APP_KEY,然后重新运行该命令以使其正常工作.

php artisan key:generate needs an existing key to work. Fill the APP_KEY with 32 characters and rerun the command to make it work.

通过laravel新创建的,带有已删除APP_KEY的应用可以运行php artisan key:generate,而不会由于某些原因而出现问题.

A newly created app via laravel new with a deleted APP_KEY can run php artisan key:generate without issue for some reason.

一年后 真正的问题在于2个附加的提供程序服务. boot()函数编写错误,从而导致了问题.仍不能完全确定为什么它不起作用,但我会尽力为以后可能遇到相同问题的人找出答案.

Edit a year later: The real problems lays in 2 added provider services. The boot() functions are badly written which causes the problem. Still not exactly sure why it doesn't work but I'll try and figure it out for somebody who may have the same problem later.

有问题的两个文件

<?php

namespace App\Providers;

use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Routing\ResponseFactory;

class ResponseServiceProvider extends ServiceProvider
{
    public function boot(ResponseFactory $factory){
        parent::boot();
        $factory->macro('api', function ($data=null, $code=null, $message=null) use ($factory) {
            $customFormat = [
                'status' => 'ok',
                'code' => $code ? $code : 200,
                'message' => $message ? $message : null,
                'data' => $data
            ];

            if ($data instanceof LengthAwarePaginator){
                $paginationData = $data->toArray();
                $pagination = isset($paginationData['current_page']) ? [
                    "total" => $paginationData['total'],
                    "per_page" => (int) $paginationData['per_page'],
                    "current_page" => $paginationData['current_page'],
                    "last_page" => $paginationData['last_page'],
                    "next_page_url" => $paginationData['next_page_url'],
                    "prev_page_url" => $paginationData['prev_page_url'],
                    "from" => $paginationData['from'],
                    "to" => $paginationData['to']
                ] : null;

                if ($pagination){
                    $customFormat['pagination'] = $pagination;
                    $customFormat['data'] = $paginationData['data'];
                }
            }

            return $factory->make($customFormat);
        });
    }

    public function register(){
        //
    }
}

<?php

namespace App\Providers;

use App\Http\Controllers\Auth\SocialTokenGrant;
use Laravel\Passport\Bridge\RefreshTokenRepository;
use Laravel\Passport\Bridge\UserRepository;
use Laravel\Passport\Passport;
use Laravel\Passport\PassportServiceProvider;
use League\OAuth2\Server\AuthorizationServer;

/**
 * Class CustomQueueServiceProvider
 *
 * @package App\Providers
 */
class SocialGrantProvider extends PassportServiceProvider{
    /**
//     * Bootstrap any application services.
//     *
//     * @return void
//     */
    public function boot(){
        parent::boot();
        app(AuthorizationServer::class)->enableGrantType($this->makeSocialRequestGrant(), Passport::tokensExpireIn());
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register(){
    }

    /**
     * Create and configure a SocialTokenGrant based on Password grant instance.
     *
     * @return SocialTokenGrant
     */
    protected function makeSocialRequestGrant(){
        $grant = new SocialTokenGrant(
            $this->app->make(UserRepository::class),
            $this->app->make(RefreshTokenRepository::class)
        );
        $grant->setRefreshTokenTTL(Passport::refreshTokensExpireIn());
        return $grant;
    }
}

这篇关于"php artisan key:generate"给出“未指定应用程序加密密钥".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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