In Laravel, APP_KEY
plays a similar role to SECRET_KEY
in Django, where it’s a required value for certain operations the framework uses. It’s generated for you if you create a new laravel app via the installer, but I’m providing all the code.
The reason we need the user to have PHP and Composer installed is the php artisan key:generate
command later to generate the APP_KEY
.
But. I can remove the composer
dependency by getting the user to generate their own APP_KEY
to put into the .env
file with pure PHP:
php -r "echo 'APP_KEY=base64:'.base64_encode(random_bytes(32));"
The user needs Node and NPM on their system to do the static asset compilation (because these aren’t installed in the production container). Given this dependency, the user could use node to generate the key instead:
node -e "require('crypto').randomBytes(32,function(o,e){console.log('APP_KEY=base64:'+e.toString('base64'))});"
Or, without node or php, if we can presume openssl
on a user’s machine (or direct them to run in Cloud Shell):
echo "APP_KEY=base64:$(openssl rand -base64 32)"
At some point this demo will be live, then I can show y’all how to deploy Laravel without having to run it locally.
Of course you probably would want to have it run locally, but that’s not a dependency for deployment 😀