Laravel 5 Application Key
Solution 1:
This line in your app.php
, 'key' => env('APP_KEY', 'SomeRandomString'),
, is saying that the key for your application can be found in your .env
file on the line APP_KEY
.
Basically it tells Laravel to look for the key in the .env
file first and if there isn't one there then to use 'SomeRandomString'
.
When you use the php artisan key:generate
it will generate the new key to your .env
file and not the app.php
file.
As kotapeter said, your .env
will be inside your root Laravel directory and may be hidden; xampp/htdocs/laravel/blog
Solution 2:
You can generate a key
by the following command:
php artisan key:generate
The key will be written automatically in your .env
file.
APP_KEY=YOUR_GENERATED_KEY
If you want to see your key
after generation use --show
option
php artisan key:generate --show
Note: The .env
is a hidden file in your project folder.
Solution 3:
Just as another option if you want to print only the key (doesn't write the .env file) you can use:
php artisan key:generate --show
Solution 4:
From the line
'key' => env('APP_KEY', 'SomeRandomString'),
APP_KEY
is a global environment variable that is present inside the .env
file.
You can replace the application key if you trigger
php artisan key:generate
command. This will always generate the new key.
The output may be like this:
Application key [Idgz1PE3zO9iNc0E3oeH3CHDPX9MzZe3] set successfully.
Application key [base64:uynE8re8ybt2wabaBjqMwQvLczKlDSQJHCepqxmGffE=] set successfully.
Base64 encoding should be the default in Laravel 5.4
Note that when you first create your Laravel application, key:generate is automatically called.
If you change the key be aware that passwords saved with Hash::make()
will no longer be valid.
Solution 5:
For me the problem was in that I had not yet ran composer update
for this new project/fork. The command failed silently, nothing happened.
After running composer update
it worked.