Javier Eguiluz
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)%"
        # ...
Published in #Living on the edge