- Laravel Version: 9.36.2
- PHP Version: 8.1.12
- Database Driver & Version: MariaDB 10.6.10
Description:
When APP_KEY is not set in .env, php artisan key:generate returns:
INFO Application key set successfully.
However, APP_KEY is not set.
Instead, I would expect Laravel to either:
- Return an error message, instructing the user to set an empty
APP_KEY
- Add
APP_KEY
Steps To Reproduce:
- Create
.env without APP_KEY
- Run
php artisan key:generate
Demonstration of the issue:
acme@acme-test:/var/www/acme$ cat .env
APP_ENV=local
acme@acme-test:/var/www/acme$ php artisan config:cache
INFO Configuration cached successfully.
acme@acme-test:/var/www/acme$ php artisan key:generate
INFO Application key set successfully.
acme@acme-test:/var/www/acme$ cat .env
APP_ENV=local
As you can see, APP_KEY is missing from .env.
When APP_KEY is set, the command works as expected:
acme@acme-test:/var/www/acme$ cat .env
APP_ENV=local
APP_KEY=
acme@acme-test:/var/www/acme$ php artisan config:cache
INFO Configuration cached successfully.
acme@acme-test:/var/www/acme$ php artisan key:generate
INFO Application key set successfully.
acme@acme-test:/var/www/acme$ cat .env
APP_ENV=local
APP_KEY=base64:oqrt7GTMMWcQ9RgL4asXYdHKeF+rWlc4/mqTPXsMJXk=
As you can see, the empty APP_KEY value has been replaced with an app key in .env.
Description:
When
APP_KEYis not set in.env,php artisan key:generatereturns:However,
APP_KEYis not set.Instead, I would expect Laravel to either:
APP_KEYAPP_KEYSteps To Reproduce:
.envwithoutAPP_KEYphp artisan key:generateDemonstration of the issue:
As you can see,
APP_KEYis missing from.env.When
APP_KEYis set, the command works as expected:As you can see, the empty
APP_KEYvalue has been replaced with an app key in.env.