Skip to content

[DependencyInjection] feat(env processor): add doc/help on APP_SECRET env var not found exception #57422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,19 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed

if (false === $env) {
if (!$this->container->hasParameter("env($name)")) {
throw new EnvNotFoundException(sprintf('Environment variable not found: "%s".', $name));
$message = sprintf('Environment variable not found: "%s".', $name);

// Symfony internal
if ('APP_SECRET' === $name) {
$message = <<<MESSAGE
Environment variable not found: "APP_SECRET" that is needed for security reason.
Define it in your .env file via `php -r 'file_put_contents(".env", "\nAPP_SECRET=" . bin2hex(random_bytes(16)), FILE_APPEND);'` or manually as a strong and secure token
or in your vault via `php bin/console secrets:set APP_SECRET --random`
Read more at https://symfony.com/doc/current/configuration.html#configuration-based-on-environment-variables
MESSAGE;
}

throw new EnvNotFoundException($message);
}

$env = $this->container->getParameter("env($name)");
Expand Down
Loading