Get your next remote job on LaraJobs.
Laravel Security

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

Benjamin Crozat
Modified on Aug 12, 2023 0 comments Edit on GitHub
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.

Wait, there's more!

Be the first to comment!

Get help or share something of value with other readers!

Great deals for enterprise developers
  • ZoneWatcher
    Get instant alerts on DNS changes across all major providers, before your customers notice.
    25% off for 12 months using the promo code CROZAT.
    Try ZoneWatcher for free
  • Quickly build highly customizable admin panels for Laravel projects.
    20% off on the pro version using the promo code CROZAT.
    Try Backpack for free
  • Summarize and talk to YouTube videos. Bypass ads, sponsors, chit-chat, and get to the point.
    Try Nobinge →
  • Monitor the health of your apps: downtimes, certificates, broken links, and more.
    20% off the first 3 months using the promo code CROZAT.
    Try Oh Dear for free
  • Keep the customers coming; monitor your Google rankings.
    30% off your first month using the promo code WELCOME30
    Try Wincher for free →
The latest community links
- / -