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?
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.
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.
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 the config method? The config method allows your application to get or set values in all files that are in the config directory.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With