Wednesday, November 23, 2022

"No Application Encryption Key Has Been Specified" Error in Laravel Application

 While creating a new laravel application from the begining, you only need the below things:

  • A terminal
  • PHP-7.0 installed
  • composer installed and available in your path
  • npm installed aad available in your path.

After all the above installed in your computer , You can create a new Laravel project from the command prompt:

composer create-project laravel/laravel  Myapplication

Now you can run:

php artisan serve

This should give you a URL to view, so click on this and open it in your browser. This should show the default Laravel screen or Page. But some time you get a Error in the browser as " No application Encryption Key has been specified" 



This will happen if the application key is empty in .env file or the key is corrupted.
In such case you need to follow the below steps to solve this issue:

1. Generate application key by running the below command in your command prompt:
    php artisan key:generate




2. Now you can see. .env file your app key is set to a key if its empty. or its updated.

3. Now you can run php artisan serve



 4. And go to the browser and check the link, You will be able to see the default laravel page showing



Even if you see the error, you need to clear the cache with the command 
php artisan config:cache

And after this, run php artsan serve and you will be able to see the laravel default page. Hope this helps.

No comments: