How to Solve Error Message No application encryption key has been specified

Posted on

Introduction

This is an article for solving the problem because of the key has not been generated. The problem arise upon configuring a new project or application using Laravel as its framework. After performing ‘composer install’ to build the project and downloading the necessary modules, this error occur. Accessing the application via browser generates the following page with a specific error message as follows :

 

 

The error message is ‘No application encryption key has been specified’.

 

Solving the Problem

The solution for the above problem is actually quite simple. Just execute a specific command in the command line using the ‘artisan’ tool or utility. The following is the command execution :

php artisan key:generate

The execution: of the above command exist as follows :

[root@hostname ~]# php artisan key:generate
Application key set successfully.
[root@hostname ~]# 

The main difference exist in the application configuration file by default. Normally, laravel has a file configuration with the name of ‘.env’ in its root directory. Creating the file configuration from the template where it is available from a file with the name of ‘.env.example’ turns out generate an error. It is because the APP_KEY by default does not have any value in the laravel configuration file. The content of the .env by default exist as follows :

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
...

The above content is only part of the content retrieved from the ‘.env’ file configuratioin for the application based on Laravel framework. It is the original file before the execution of the ‘php artisan key:generate’ command. After executing the command which is also solving the problem, the APP_KEY will have a new assigned value of the generated key¬† in the .env file laravel framework for the application configuration as follows :

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:dG/v+Dc73X/5wB4kKn/gjuaJucxR+TMrcTFuygOdWCQ=
APP_DEBUG=true
APP_URL=http://localhost

Since the app key is exist as a new line of configuration in the .env file configuration for the web application based on Laravel framework, the problem is finally over. The error is no longer appear in the main page of the web application based on Laravel framework.

Leave a Reply