Laravel 5 Application Key
PhpLaravelLaravel 5.1Php Problem Overview
I am new to Laravel. I just started it tonight. Actually, I have the following code:
'key' => env('APP_KEY', 'SomeRandomString'),
In xampp/htdocs/laravel/blog/config/app.php.
I want to change this key to 32-bit by cmd as:
xampp\htdocs\laravel/blog>php artisan key:generate
It generates the key but could not replace/update in xampp/htdocs/laravel/blog/config/app.php.
Php Solutions
Solution 1 - Php
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 - Php
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 - Php
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 - Php
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.
Hash::make()
will no longer be valid.
If you change the key be aware that passwords saved with Solution 5 - Php
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.