Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there 2 APP Key in Laravel? .env and config/app.php

I installed Laravel 5 via composer and after the installation the App Key was generated automatically. I went to .env file and I could see the APP_KEY there. However, I also noticed that there is another APP_KEY inside config/app.php like this:

'key' => env('APP_KEY', 'SomeRandomString'),
'cipher' => 'AES-256-CBC',

My newbie questions are:

1) Why is there App keys in 2 different locations?

2) When App Key was generated, why didnt it update the config/app.php file as well?

3) Do I need to manually paste the .env App key into the config/app.php file too or will that be not necessary as long as .env has it there?

4) During future updates, do I need to keep adding the App key into app.php file? Meaning, would it get reseted during updates?

like image 712
Neel Avatar asked Jul 05 '15 07:07

Neel


People also ask

What is use of app key in Laravel?

Laravel Key Generate is a command and it assists by setting the APP_KEY value in the . env file. This command is directly and by default run when a composer create-project Laravel command is generated.

What is app key used for?

Application Keys are credentials that you can manage. You can have one or more Application Keys per Application ID for segmenting and tracking purposes. If you discover that your credentials have been compromised, you can create a new Application Key and delete the compromised one.

For what do the .env is used in Laravel?

Laravel's default .env file contains some common configuration values that may differ based on whether your application is running locally or on a production web server. These values are then retrieved from various Laravel configuration files within the config directory using Laravel's env function.

What is config () in Laravel?

What is the config method? The config method allows your application to get or set values in all files that are in the config directory.


1 Answers

The value set in config/app.php is used if there is no value in the .env file. If you have set the app key in the .env file, the second argument in app.php is ignored.

like image 80
baao Avatar answered Oct 14 '22 04:10

baao