Generate Application Key in Laravel 10

Generate Application Key in Laravel 10

Securing sensitive data is a top priority for any web application, and Laravel takes this matter seriously. Laravel uses application key for encryption and decryption of critical components like cookies, sessions, and CSRF tokens. Laravel stores the application key in the APP_KEY environment variable within the .env file that is located in the root directory. This tutorial demonstrates how to generate application key in Laravel 10.

Upon installing Laravel using the installer, it automatically generates the application key along with other necessary dependencies. However, if you decided to change it or encounter a situation where it hasn't been set, you can generate an application key using the following command:

php artisan key:generate

Executing this command generates a random string and stores it as the APP_KEY inside the .env file. Typically, we need to execute this command when cloning a Laravel application, as the cloned project lacks the .env file.

Now, clear the configuration cache using the following command:

php artisan config:cache

Leave a Comment

Cancel reply

Your email address will not be published.