Lumen Micro Framework => php artisan key:generate

后端 未结 12 821
遥遥无期
遥遥无期 2021-01-30 00:59

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

One of my first steps was to look into the .env.example file and make a copy of it to have my

相关标签:
12条回答
  • 2021-01-30 01:26

    1.Open your terminal setup file:

    vim ~/.zshrc
    

    2.Create an alias for generating random strings:

    # Lumen Key Generate
    alias lumen-key="php -r \"require 'vendor/autoload.php'; echo base64_encode(str_random(32)).PHP_EOL;\""
    

    3.Get a key whenever you need:

    ~/your-lumen-project via                                                                     
    0 讨论(0)
  • 2021-01-30 01:27

    For me the easiest way to generate a Lumen key is typing on console one of these commands:

    date | md5
    date | md5sum
    

    or

    openssl rand -base64 24

    depending of your environment. In my case, I aways use date | md5 on mac

    0 讨论(0)
  • 2021-01-30 01:29

    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);
    });
    

    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

    0 讨论(0)
  • 2021-01-30 01:32

    Run php -a to start up interactive php playground.

    Then run echo substr(md5(rand()), 0, 32); to generate a 32 character string.

    You can then copy/paste into the .env file.

    0 讨论(0)
  • 2021-01-30 01:34

    To generate key and use laravel command you need to install one package. The details are as below:

    1. You have to install package composer require flipbox/lumen-generator
    2. You have to add $app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class); into bootstrap/app.php file.

    Link: https://github.com/flipboxstudio/lumen-generator

    0 讨论(0)
  • 2021-01-30 01:36

    Firstly, you have to register your key generator command, put this Lumen Key Generator Commands to app/Console/Commands/KeyGenerateCommand.php. To make this command available in artisan, change app\Console\Kernel.php:

    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        'App\Console\Commands\KeyGenerateCommand',
    ];
    

    After that, configure your application so that Illuminate\Config\Repository instance has app.key value. To do this, change bootstrap/app.php:

    <?php
    
    require_once __DIR__.'/../vendor/autoload.php';
    
    Dotenv::load(__DIR__.'/../');
    
    /*
    |--------------------------------------------------------------------------
    | Create The Application
    |--------------------------------------------------------------------------
    |
    | Here we will load the environment and create the application instance
    | that serves as the central piece of this framework. We'll use this
    | application as an "IoC" container and router for this framework.
    |
    */
    
    $app = new Laravel\Lumen\Application(
        realpath(__DIR__.'/../')
    );
    
    $app->configure('app');
    

    After that, copy your .env.example file to .env:

    cp .env.example .env
    

    Ignore this step if you already use .env file.

    Enjoy you key:generate command via:

    php artisan key:generate
    

    Edit

    You may use Lumen Generator. It covers so much commands you are missing from Laravel.

    0 讨论(0)
提交回复
热议问题