Benjamin Crozat “Heard about Sevalla? They let you deploy PHP apps with ease.” Claim $50 →

Fix "No application encryption key has been specified." in Laravel

2 minutes read

Fix "No application encryption key has been specified." in Laravel

How to fix the “No application encryption key has been specified.” error message in Laravel

“No application encryption key has been specified.” is quite common in Laravel, and it means exactly what it says: there’s no encryption key specified for your application.

To fix “No application encryption key has been specified.”, run the command php artisan key:generate.

Understanding the “No application encryption key has been specified.” error message in Laravel

Laravel uses an encryption key to secure sessions, cookies, serialized data, password hashes, and other encrypted data.

If this key is not set, Laravel cannot guarantee the security of these things, hence the error message.

This is a big problem, especially in production where sensitive data must be encrypted. Here’s how to fix the issue:

  1. Generate an application key: Open a terminal, navigate to your project directory, and run the command php artisan key:generate. This command will generate a new random key for your application. To be safe, run php artisan config:clear just in case you previously cached the config values.
  2. Create the eventually missing .env file: The above command sets the generated key to your APP_KEY environment variable in your .env file. Laravel should automatically have created it based on .env.example at the root of your project. If you get the file_get_contents(/path/to/project/.env): Failed to open stream: No such file or directory error message, it means it didn’t. You must create it yourself by running cp .env.example .env for instance.

Remember, it’s important to keep your APP_KEY secret and not to commit your .env file to version control systems.

Learn more on Laravel’s documentation.

Bonus: fix the “No application encryption key has been specified.” error message in Laravel with one click

As I said, the “No application encryption key has been specified.” error message is extremely frequent in Laravel.

So much that Laravel offers you to fix it with just a single click!

Did you notice the button? Try it, it’s so convenient! 👍

No application encryption key has been specified.


Did you like this article? Then, keep learning:

Would you mind helping me reach more people by sharing this article on social media?

0 comments

Guest

Markdown is supported.

Hey, you need to sign in with your GitHub account to comment. Get started →

Great deals for developers