Skip to content

Instantly share code, notes, and snippets.

@wesamly
Last active June 28, 2022 06:32
Show Gist options
  • Save wesamly/8534c83dccdc645a8b8470ad39e820f2 to your computer and use it in GitHub Desktop.
Save wesamly/8534c83dccdc645a8b8470ad39e820f2 to your computer and use it in GitHub Desktop.
Lumen generate app key code
<?php
// Use command line in generate.sh
// Generation code line by line
include __DIR__ . "/vendor/autoload.php";
include __DIR__ . "/bootstrap/app.php";
// Check https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/Console/KeyGenerateCommand.php
$key = "base64:" . base64_encode(Illuminate\Encryption\Encrypter::generateKey(config("app.cipher")));
file_put_contents(
__DIR__ . "/.env",
preg_replace(
"/^APP_KEY\=/m",
"APP_KEY=" . $key,
file_get_contents(__DIR__ . "/.env")
)
);
# Only for empty APP_KEY
php -r 'include __DIR__."/vendor/autoload.php";include __DIR__."/bootstrap/app.php";$key="base64:".base64_encode(Illuminate\Encryption\Encrypter::generateKey(config("app.cipher")));file_put_contents(__DIR__."/.env",preg_replace("/^APP_KEY\=/m","APP_KEY=".$key,file_get_contents(__DIR__."/.env")));';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment