Skip to content

Commit 2f1dd34

Browse files
[Configuration] Add $_ENV and $_SERVER example with .env
1 parent 138546c commit 2f1dd34

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

configuration.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Configuration Formats
5858
~~~~~~~~~~~~~~~~~~~~~
5959

6060
Unlike other frameworks, Symfony doesn't impose a specific format on you to
61-
configure your applications, but lets you choose between YAML, XML and PHP.
61+
configure your applications, but lets you choose between YAML, XML and PHP.
6262
Throughout the Symfony documentation, all configuration examples will be
6363
shown in these three formats.
6464

@@ -721,6 +721,12 @@ This file should be committed to your repository and (due to that fact) should
721721
only contain "default" values that are good for local development. This file
722722
should not contain production values.
723723

724+
Your env vars can be accessed in your code thanks to PHP super
725+
globals ``$_ENV`` and ``$_SERVER``. Both are equivalent::
726+
727+
$databaseUrl = $_ENV['DATABASE_URL']; // mysql://db_user:db_password@127.0.0.1:3306/db_name
728+
$env = $_SERVER['APP_ENV']; // prod
729+
724730
In addition to your own env vars, this ``.env`` file also contains the env vars
725731
defined by the third-party packages installed in your application (they are
726732
added automatically by :ref:`Symfony Flex <symfony-flex>` when installing packages).

0 commit comments

Comments
 (0)