Skip to content

APP_KEY not set when not in .env despite "Application key set" message #44917

@WilliamDEdwards

Description

@WilliamDEdwards
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions