laravel 4: key not being generated with artisan

2019-01-23 13:52发布

问题:

When running

php artisan key:generate

I can see the generated key in my shell, but the variable 'key' in app.php remains empty.

Running on localhost with windows-apache-php 5.4 - mysql.

Never had this problem before with laravel 4 beta version.

回答1:

Had the same problem ...

  1. Opened app.php
  2. Remove the entry that says 'YourSecretKey!!!'
  3. Ran 'php artisan key:generate'

Showed me a key in the console, but nothing in app.php!

Solution is ... unlike Laravel 3, don't delete the default YourSecretKey!!! in app.php, just run the command and it will work.

Hope this helps.

Bagwaa



回答2:

You should not remove the original key, just go to your project directory and run

php artisan key:generate

it will work if you don't touch the previous key.



回答3:

first type any 32 character like 'hyhyhGGyhyhyhyhy23hyhy23hyhy23hy' this and then re execute the command in terminal/cmd.

Step 1:

go to app ---> Config --> app.php

step 2:

'key' => '10101010101010101010101010101010', type any 32 digit or character in that place.

step 3:

go to terminal / cmd & type : "php artisan key:generate" press enter

step 4:

see the key has been changed :)

[ It is because in Laravel 4 By using "php artisan key:generate" we simply can replace the default key any time. But if it is an empty space it can not be able to hold the place. ]

Enjoy coding :) \m/



回答4:

The key generator will only update the APP_KEY in the .env file.

'key' => env('APP_KEY', 'YourSecretKey'), 

config/app.php this is reading the APP_KEY from your .env file. The second parameter is a fallback.



回答5:

I was having the same issue. From my project directory I noticed I had the .env file, when I opened the project in atom (my code editor) I noticed that file appeared as .env.txt, I removed the .txt part and ran the command. It worked for me.