8000 Clarifying that .env can be used on production by weaverryan · Pull Request #10548 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content
8000

Clarifying that .env can be used on production #10548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Clarifying that .env can be used on production
  • Loading branch information
weaverryan committed Oct 24, 2018
commit bc5ad90f54c62fb03b98baac561b61f4eb11c760
27 changes: 19 additions & 8 deletions deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,27 @@ B) Configure your Environment Variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Most Symfony applications read their configuration from environment variables.
While developing locally, you'll usually store these in a ``.env`` file. But on
production, instead of creating this file, you should set *real* environment variables.
While developing locally, you'll usually store these in a ``.env`` file. On production,
you have two options:

How you set environment variables, depends on your setup: they can be set at the
command line, in your Nginx configuration, or via other methods provided by your
hosting service.
1. Create "real" environment variables. How you set environment variables, depends
on your setup: they can be set at the command line, in your Nginx configuration,
or via other methods provided by your hosting service.

At the very least you need to define the ``APP_ENV=prod`` environment variable
to run the application in ``prod`` mode, but depending on your application you
may need to define other env vars too.
2. Or, create a ``.env`` file just like your local development (see note below)

There is no significant advantage to either of the two options: use whatever is
most natural in your hosting environment.

.. note::

If you use the ``.env`` file on production, you may need to move your
``symfony/dotenv`` dependency from ``require-dev`` to ``require`` in ``composer.json``:

.. code-block:: terminal

$ composer remove symfony/dotenv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have problems on this first command:

  1. First, it causes Composer to print a warning and ask for confirmation:
    symfony/dotenv could not be found in require but it is present in require-dev
    Do you want to remove it from require-dev [yes]? 
    
    To avoid that, you can add --dev, i.e.: composer remove --dev symfony/dotenv
  2. Then (either after confirming or with --dev), it causes an error from the Symfony console:
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Restricting packages listed in "symfony/symfony" to "4.1.*"
    Package operations: 0 installs, 0 updates, 1 removal
      - Removing symfony/dotenv (v4.1.6)
    Writing lock file
    Generating autoload files
    Executing script cache:clear [KO]
     [KO]
    Script cache:clear returned with error code 255
    !!  
    !!  Fatal error: Uncaught RuntimeException: APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file. in /usr/src/myapp/bin/console:20
    
  3. It is actually useless: thanks to When requiring a package remove it from require-dev and vice versa composer/composer#2893, composer require symfony/dotenv alone also removes the package from require-dev (which is closer to a "move" than remove-then-reinstall).

So what about simply removing this line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #11112

$ composer reuire symfony/dotenv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(typo on "require" fixed in d45f041)


C) Install/Update your Vendors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
0