From 271313c0257978747fa163246f6f6aa811f7fbde Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 7 Apr 2018 13:04:21 +0200 Subject: [PATCH] Documentation: custom env variables --- docs/configuration-files/env-file.rst | 4 +- .../custom-environment-variables.rst | 53 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 docs/tutorials/custom-environment-variables.rst diff --git a/docs/configuration-files/env-file.rst b/docs/configuration-files/env-file.rst index a429c29e..8824a3d8 100644 --- a/docs/configuration-files/env-file.rst +++ b/docs/configuration-files/env-file.rst @@ -1021,7 +1021,7 @@ The PHP container itself does not offer any variables, however you can add any k variable into the ``.env`` file which will automatically be available to the started PHP container and thus in any of your PHP projects. -If your application requires are variable to determine if it is run under development or +If your application requires a variable to determine if it is run under development or production, for example: ``APPLICATION_ENV``, you can just add this to the ``.env`` file: .. code-block:: bash @@ -1051,6 +1051,8 @@ This will then output ``development``. .. note:: Add as many custom environment variables as you require. +.. seealso:: :ref:`tutorial_custom_environment_variables` + Web server ---------- diff --git a/docs/tutorials/custom-environment-variables.rst b/docs/tutorials/custom-environment-variables.rst new file mode 100644 index 00000000..fe2e5343 --- /dev/null +++ b/docs/tutorials/custom-environment-variables.rst @@ -0,0 +1,53 @@ +.. _tutorial_custom_environment_variables: + +**************************** +Custom environment variables +**************************** + +If your application requires a variable to determine if it is run under development or +production, you can easily add it and make PHP aware of it. + + +**Table of Contents** + +.. contents:: :local: + + +Add custom environment variables +================================ + +This is fairly simple. Any variable inside the ``.env`` file is considered an environment variable +and automatically known to PHP. + +If you for example require a variable ``APPLICATION_ENV``, with a value of ``production``, you +would add the following to the ``.env`` file: + +.. code-block:: bash + :caption: .env + :name: .env + :emphasize-lines: 1 + + APPLICATION_ENV=production + +You need to restart the Devilbox for the changes to take effect. + +.. note:: + There is already a proposed section inside the ``.env`` file at the very bottom + to add you custom variables to differentiate them from the Devilbox required variables. + + +Use custom environment variables +================================ + +Accessing the above defined environment variable on the PHP side is also fairly simple. +You can use the PHP's built-in function ``getenv`` to obtain the value: + +.. code-block:: php + :caption: index.php + :name: index.php + :emphasize-lines: 3 + +