From 448be856c26e5e372fc4f9cc5612cd9d7112313a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 19 Sep 2023 12:07:51 +0200 Subject: [PATCH] Prioritize the dump-env Composer command --- configuration.rst | 48 ++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/configuration.rst b/configuration.rst index 70dd76bca27..89a8e047e28 100644 --- a/configuration.rst +++ b/configuration.rst @@ -831,33 +831,43 @@ In production, the ``.env`` files are also parsed and loaded on each request. So the easiest way to define env vars is by creating a ``.env.local`` file on your production server(s) with your production values. -To improve performance, you can optionally run the ``dotenv:dump`` command (available -in :ref:`Symfony Flex ` 1.2 or later). The command is not registered -by default, so you must register first in your services: +To improve performance, you can optionally run the ``dump-env`` Composer command: -.. code-block:: yaml +.. code-block:: terminal - # config/services.yaml - services: - Symfony\Component\Dotenv\Command\DotenvDumpCommand: - - '%kernel.project_dir%/.env' - - '%kernel.environment%' + # parses ALL .env files and dumps their final values to .env.local.php + $ composer dump-env prod -In PHP >= 8, you can remove the two arguments when autoconfiguration is enabled -(which is the default): +.. sidebar:: Dumping Environment Variables without Composer -.. code-block:: yaml + If you don't have Composer installed in production, you can use the + ``dotenv:dump`` command instead (available in :ref:`Symfony Flex ` + 1.2 or later). The command is not registered by default, so you must register + first in your services: - # config/services.yaml - services: - Symfony\Component\Dotenv\Command\DotenvDumpCommand: ~ + .. code-block:: yaml -Then, run the command: + # config/services.yaml + services: + Symfony\Component\Dotenv\Command\DotenvDumpCommand: + - '%kernel.project_dir%/.env' + - '%kernel.environment%' -.. code-block:: terminal + In PHP >= 8, you can remove the two arguments when autoconfiguration is enabled + (which is the default): - # parses ALL .env files and dumps their final values to .env.local.php - $ php bin/console dotenv:dump prod + .. code-block:: yaml + + # config/services.yaml + services: + Symfony\Component\Dotenv\Command\DotenvDumpCommand: ~ + + Then, run the command: + + .. code-block:: terminal + + # parses ALL .env files and dumps their final values to .env.local.php + $ php bin/console dotenv:dump prod After running this command, Symfony will load the ``.env.local.php`` file to get the environment variables and will not spend time parsing the ``.env`` files.