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 .env
file. There is a variable APP_KEY just like there is in Laravel. Now I tried out the simple command php artisan key:generate
to get my new key But I ran into the following error message
This may result in extra foreign key columns if your properties return entities. For some reason, Slauma's InverseProperty attribute suggestion didn't work. For anyone else landing here looking for a solution, if you've tried the previous answers and are still getting an extra foreign key column, look for any properties you may have defined further down your POCO class that you did not intend to map to DB fields. Even if they contain code blocks, as with complex get accessors, Entity Framework will try to map them to the database somehow. Ef6 not generating foreign key name correctly.
[InvalidArgumentException]There are no commands defined in the 'key' namespace.
Does some one know how I can generate keys for Lumen?
Update with solution
You can create a custom driver if you want to use one of these additional adapters in your Laravel application. In order to set up the custom filesystem you will need a Flysystem adapter. Let's add a community maintained Dropbox adapter to our project: composer require spatie/flysystem-dropbox.
Craftable is a Laravel-based open-source toolkit for building administration interfaces. It ships with powerful CRUD generator to speed up the development of your CMS, CRM or other back-office systems. May 29, 2017 Laravel is full of little tricks, and quick ways to generate code with Artisan. One of the recent ones I've found is when you're creating a CRUD record and need to create Model + Controller. You don't need two separate commands for that. Laravel 4: key not being generated with artisan. I can see the generated key in my shell, but the variable 'key' in app.php remains empty. Running on localhost with windows-apache-php 5.4 - mysql. Never had this problem before with laravel 4 beta version.
So I found my favorite solution for this problem. On the command line (Linux) I run php -r 'echo md5(uniqid()).'n';'
what gives me something like this 7142720170cef01171fd4af26ef17c93
.
If you are going to use Lumen more often, you may want to create an alias in your .bashrc
, which is located in your home directory /home/USERNAME
. To do so, you can open the file with nano ~/.bashrc
or vi ~/.bashrc
and copy the following alias at the end of the file, alias phpkey='php -r 'echo md5(uniqid()).'n';'
. Now you can use the command phpkey
which will give you a 32 character long random string 🙂
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:
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
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 appConsoleKernel.php
:
After that, configure your application so that IlluminateConfigRepository
instance has app.key
value. To do this, change bootstrap/app.php
:
After that, copy your .env.example
file to .env
:
Ignore this step if you already use .env
file.
Enjoy you key:generate
command via:
You may use Lumen Generator. It covers so much commands you are missing from Laravel.
An easy solution is just running PHP code from the terminal (without using tinker
, because that is not available with Lumen):
It uses Laravel’s Str::random()
function that makes use of the secure random_bytes()
function.
The APP_KEY generation is a step of development process (I don’t think that creating temporarily routes is a practical way to do it). The function str_random
can help us, but this function is part of Laravel/Lunmen framework.
I recommend running tinker
php artisan tinker
and then run the function
>>> str_random(32)
The result is the key you’re looking for.
=> 'y3DLxnEczGWGN4CKUdk1S5GbMumU2dfH'
For me the easiest way to generate a Lumen key is typing on console one of these commands:
or
openssl rand -base64 24
depending of your environment. In my case, I aways use date md5
on mac
This answer was inspired by @thomas-venturini ‘s update to the question. Here’s a bash script that takes care of creating .env
and updating it with an APP_KEY
using the aforementioned PHP command and the UNIX sed
command:
Hope someone finds this useful.
Tags: phpphp
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upHave a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It seems that after this commit https://github.com/laravel/framework/commit/370ae34d41362c3adb61bc5304068fb68e626586 command |
It's not broken, the key is base64 encoded. |