Cover image for How generate a Laravel APP_KEY with OpenSSL

How generate a Laravel APP_KEY with OpenSSL

gregorip02 profile image Gregori Piñeres Updated on ・1 min read

Hello everyone, today I will show you a little trick that I use frequently in my scripts to create a Laravel application key commonly generated with artisan.

It's simple, with the help of the openssl package we can generate a random string of 32 characters and at the same time, it can be encoded in base64.

This will generate a fully valid laravel application key that you can use in your .env configuration file.

echo "base64:$(openssl rand -base64 32)"
Enter fullscreen mode Exit fullscreen mode

Thanks for reading this little tip, don't forget to share it on your social networks or with your development team.

We read soon.

Posted on by:

gregorip02 profile

Gregori Piñeres


PHP & Typescript programmer 🐳


Editor guide

Hi, thanks for sharing this tip. Just curious about the reason behind it? Or is it just another way to do it?


On one occasion I had to do it this way to generate a secret file in a Laravel application in Kubernetes. Obviously this is another way to do it without having the PHP interpreter installed locally. However you do it, the result is the same.