Reputation: 4951
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.
Upvotes: 90
Views: 282149
Reputation: 8350
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.
Upvotes: 102
Reputation: 3749
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
Upvotes: 45
Reputation: 11398
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.
Upvotes: 1
Reputation: 46479
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.Upvotes: 1
Reputation: 16359
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
Upvotes: 114