New in Symfony 3.3: Deprecated the special SYMFONY__ environment variables
April 5, 2017 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Contributed by
Javier Eguiluz
in #21889.
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)%"
# ...
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
@Dennis you are affected only if the env name starts with "SYMFONY__" (2 underscores), so "SYMFONY_" (1 underscore) is fine.