The environment variables whose names start with SYMFONY__
are treated in a
special way by Symfony. They allow to set parameters in the service container
using environment variables. For example, if you define the
SYMFONY__KERNEL__CHARSET
env variable, Symfony uses it to set the value of
the kernel.charset
parameter.
In Symfony 3.2 we introduced proper support for runtime environment variables
so these special SYMFONY__
variables are no longer needed. That's why they
have been deprecated in Symfony 3.3 and they won't be treated in a special way
in Symfony 4.0.
Upgrading your Symfony applications is simple: instead of relying on the
automatic conversion of SYMFONY__
variables, define proper env variables and
use them in your config files. For example, if you set the database password as
follows:
1 2 3 4 5
<VirtualHost *:80>
# ...
SetEnv SYMFONY__DATABASE__PASSWORD secret_pasword
</VirtualHost>
Now you must define a regular environment variable:
1 2 3 4 5
<VirtualHost *:80>
# ...
SetEnv DATABASE_PASSWORD secret_pasword
</VirtualHost>
Then, refer to that variable in your config files using the %env(...)%
syntax:
1 2 3 4 5
# app/config/config.yml
doctrine:
dbal:
password: "%env(DATABASE_PASSWORD)%"
# ...
Hi, thanks for the post. There is a spelling mistake in the fisrt link: sontainer, i think that container.
Does this include SYMFONY_ENV? And if so, how to keep configuring that from the environment.
@Dennis Seems to only apply to double-underscored environment variables, i.e. SYMFONY__HELLO not SYMFONY_HELLO.
@philipe fixed! Thanks for reporting this issue.
@Dennis you are affected only if the env name starts with "SYMFONY__" (2 underscores), so "SYMFONY_" (1 underscore) is fine.
@Nick and @Javier huh, I didn't notice the second underscore, silly me, thanks all