have you tried ?
php artisan key:generate
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
Having a hard time with this. My app was working fine, today I restarted the laptop and receive this error:
´´´ RuntimeException No application encryption key has been specified. ´´´
I have set my key and even regenerated one using the command
´´´ APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx= ´´´
I ran all these commands php artisan cache:clear php artisan view:clear php artisan config:clear php artisan config:cache
I have also set the key in the app.php
I really tried everything, even restarted apache and checked if the mod_rewritte was enabled, all good. I have also redownloaded a new .env file to make sure it was not a problem with the file itself.
Any other ideas please?
have you tried ?
php artisan key:generate
yes, I tried unfortunately...no difference.
If you’ve regenerated the key, did you restart the server?
yes I restarted apache, laragon and even restarted the pc just in case....
it is like if Laravel cannot read the .env file anymore...it is weird.
I don't know if anyone can help but it looks like this happens to many users.....if anyone has a solution, please let me know.
I will post everything, even the keys(which I will replace later on) so you can see if anything is wrong.
This happens on both my windows 10 machines with the same installation.
In my app.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Application Name
|--------------------------------------------------------------------------
|
| This value is the name of your application. This value is used when the
| framework needs to place the application's name in a notification or
| any other location as required by the application or its packages.
|
*/
'name' => env('APP_NAME', 'MyWebsite'),
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services your application utilizes. Set this in your ".env" file.
|
*/
'env' => env('APP_ENV', 'production'),
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => env('APP_DEBUG', false),
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
*/
'url' => env('APP_URL', 'http://MyWebsite.dev'),
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'UTC',
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => 'en',
/*
|--------------------------------------------------------------------------
| Application Fallback Locale
|--------------------------------------------------------------------------
|
| The fallback locale determines the locale to use when the current one
| is not available. You may change the value to correspond to any of
| the language folders that are provided through your application.
|
*/
'fallback_locale' => 'en',
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is used by the Illuminate encrypter service and should be set
| to a random, 32 character string, otherwise these encrypted strings
| will not be safe. Please do this before deploying an application!
|
*/
'key' => env('base64:JjrFWC+TGnySY2LsldPXAxuHpyjh8UuoPMt6yy2gJ8U='),
'cipher' => 'AES-256-CBC',
/*
|--------------------------------------------------------------------------
| Logging Configuration
|--------------------------------------------------------------------------
|
| Here you may configure the log settings for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Settings: "single", "daily", "syslog", "errorlog"
|
*/
'log' => env('APP_LOG', 'single'),
'log_level' => env('APP_LOG_LEVEL', 'debug'),
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Notifications\NotificationServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
/*
* Package Service Providers...
*/
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
],
/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/
'aliases' => [
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
'Blade' => Illuminate\Support\Facades\Blade::class,
'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
'Bus' => Illuminate\Support\Facades\Bus::class,
'Cache' => Illuminate\Support\Facades\Cache::class,
'Config' => Illuminate\Support\Facades\Config::class,
'Cookie' => Illuminate\Support\Facades\Cookie::class,
'Crypt' => Illuminate\Support\Facades\Crypt::class,
'DB' => Illuminate\Support\Facades\DB::class,
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
'Event' => Illuminate\Support\Facades\Event::class,
'File' => Illuminate\Support\Facades\File::class,
'Gate' => Illuminate\Support\Facades\Gate::class,
'Hash' => Illuminate\Support\Facades\Hash::class,
'Lang' => Illuminate\Support\Facades\Lang::class,
'Log' => Illuminate\Support\Facades\Log::class,
'Mail' => Illuminate\Support\Facades\Mail::class,
'Notification' => Illuminate\Support\Facades\Notification::class,
'Password' => Illuminate\Support\Facades\Password::class,
'Queue' => Illuminate\Support\Facades\Queue::class,
'Redirect' => Illuminate\Support\Facades\Redirect::class,
'Redis' => Illuminate\Support\Facades\Redis::class,
'Request' => Illuminate\Support\Facades\Request::class,
'Response' => Illuminate\Support\Facades\Response::class,
'Route' => Illuminate\Support\Facades\Route::class,
'Schema' => Illuminate\Support\Facades\Schema::class,
'Session' => Illuminate\Support\Facades\Session::class,
'Storage' => Illuminate\Support\Facades\Storage::class,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
],
];
Now here my .env file:
APP_NAME=MyWebsite
APP_ENV=local
APP_KEY=base64:JjrFWC+TGnySY2LsldPXAxuHpyjh8UuoPMt6yy2gJ8U=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://MyWebsite.com
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=MyWebsitexxx
DB_USERNAME=MyWebsiteuserxxx
DB_PASSWORD=xxxxxxxxxxxxxxxx
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=xxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_DOMAIN=mg.MyWebsite.com
MAIL_SECRET=key-xxxxxxxxxxxxxxxxxxxxxxxxxx
[email protected]
MAIL_FROM_NAME=MyWebsite
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
The key seems to be the same in both files base64:JjrFWC+TGnySY2LsldPXAxuHpyjh8UuoPMt6yy2gJ8U=
The message I get is this:
C:\laragon\www\mywebsite\vendor\laravel\framework\src\Illuminate\Encryption\EncryptionServiceProvider.php
// want to make sure to convert them back to the raw bytes before encrypting.
if (Str::startsWith($key = $this->key($config), 'base64:')) {
$key = base64_decode(substr($key, 7));
}
return new Encrypter($key, $config['cipher']);
});
}
/**
* Extract the encryption key from the given configuration.
*
* @param array $config
* @return string
*/
protected function key(array $config)
{
return tap($config['key'], function ($key) {
if (empty($key)) {
throw new RuntimeException(
'No application encryption key has been specified.'
);
}
});
}
}
Arguments
"No application encryption key has been specified."
I have tried this: php artisan view:clear php artisan config:clear php artisan cache:clear php artisan key:generate
If there anywhere else I could check for a problem please?
I also checked the env via:
php artisan env
and get this
Current application environment: local
Any idea please? I am conpletely stuck and quiet worried if this happens on an important project.
Thank you.
Just an update, I added the key here directly:
<?php
namespace Illuminate\Encryption;
use RuntimeException;
use Illuminate\Support\Str;
use Illuminate\Support\ServiceProvider;
class EncryptionServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('encrypter', function ($app) {
$config = $app->make('config')->get('app');
// If the key starts with "base64:", we will need to decode the key before handing
// it off to the encrypter. Keys may be base-64 encoded for presentation and we
// want to make sure to convert them back to the raw bytes before encrypting.
if (Str::startsWith($key = "base64:JjrFWC+TGnySY2LsldPXAxuHpyjh8UuoPMt6yy2gJ8U=", 'base64:')) {
$key = base64_decode(substr($key, 7));
}
return new Encrypter($key, $config['cipher']);
});
}
And the app launches.....so now we now that the app is not reading the "key" in the app.php itself or .env.....what could cause this please?
The env() helper searches the .env file for a key=value pair by key, not by value. env("base64:JjrFWC+TGnySY2LsldPXAxuHpyjh8UuoPMt6yy2gJ8U=") would search the file for a property with the key base64:JjrFWC+TGnySY2LsldPXAxuHpyjh8UuoPMt6yy2gJ8U=, which doesn't exist, and even if it did would be invalid.
What you want to do is something like this
//in config/app.php
'key' => env(APP_KEY);
//in .env (unchanged)
APP_KEY=base64:JjrFWC+TGnySY2LsldPXAxuHpyjh8UuoPMt6yy2gJ8U=
As a side note, your encryption key is supposed to be secret so I'd suggest generating a new one and not posting it anywhere in the future.
the syntax looks wrong in app.php
you seem to be trying to load a key from env with the actual key as it's name
I can't check a default app at the moment but I would expect more like 'key' => env('APP_KEY'),
YES!!!!!!!!!!!!!!!!!!!Thank you so much to both of you!!!! You are right, I added the key manually many days ago on machine 1, but then only got the changes when I used git on machine 2 many days later(and reloaded the config cache only at that time), this is why I was so confused......
Wow, thank you so much!!! I wish I could put both your answers as the best..... You saved me hours of searching....
Let's take it on a good note, having problems like this and looking for hours for an answer made me discover many parts of the app which I did not know about.
for what its worth
i had a simular issue where .env had wrong permissions. Using CHMOD on .env fixed the problem for me
KR Tom
@boubou what was the solution?
i think no need to create it manually just add
APP_KEY=
in your .env file
and than run
php artisan key:generate
it will generate key for you
@zahidgopang i think you will find that the OP did that THREE YEARS AGO
I had this error inside a form. Every time I type in my input field with a wire:model, it keeps showing the "No application encryption key has been specified" error in my browser's console. What I did was add wire:key on every input field. It solved my problem. I hope this helps anyone who came across this error.
you can try to run
composer dump-autoload
it happens to me, and my solution is to dump the composer.
I hope it can help
Please or to participate in this conversation.