Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Configuration
  4. Nov 2018 Changes to .env & How to Update
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

Table of Contents

  • What Changed Exactly?
  • Updating My Application

Nov 2018 Changes to .env & How to Update

Edit this page

Warning: You are browsing the documentation for Symfony 5.3, which is no longer maintained.

Read the updated version of this page for Symfony 6.2 (the current stable version).

Nov 2018 Changes to .env & How to Update

In November 2018, several changes were made to the core Symfony recipes related to the .env file. These changes make working with environment variables easier and more consistent - especially when writing functional tests.

If your app was started before November 2018, your app does not require any changes to keep working. However, if/when you are ready to take advantage of these improvements, you will need to make a few small updates.

What Changed Exactly?

But first, what changed? On a high-level, not much. Here's a summary of the most important changes:

  • A) The .env.dist file no longer exists. Its contents should be moved to your .env file (see the next point).
  • B) The .env file is now committed to your repository. It was previously ignored via the .gitignore file (the updated recipe does not ignore this file). Because this file is committed, it should contain non-sensitive, default values. The .env can be seen as the previous .env.dist file.
  • C) A .env.local file can now be created to override values in .env for your machine. This file is ignored in the new .gitignore.
  • D) When testing, your .env file is now read, making it consistent with all other environments. You can also create a .env.test file for test-environment overrides.
  • E) One further change to the recipe in January 2019 means that your .env files are always loaded, even if you set an APP_ENV=prod environment variable. The purpose is for the .env files to define default values that you can override if you want to with real environment values.

There are a few other improvements, but these are the most important. To take advantage of these, you will need to modify a few files in your existing app.

Updating My Application

If you created your application after November 15th 2018, you don't need to make any changes! Otherwise, here is the list of changes you'll need to make - these changes can be made to any Symfony 3.4 or higher app:

  1. Update your public/index.php file to add the code of the public/index.php file provided by Symfony. If you've customized this file, make sure to keep those changes (but add the rest of the changes made by Symfony).
  2. Update your bin/console file to add the code of the bin/console file provided by Symfony.
  3. Update .gitignore:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # .gitignore
      # ...
    
      ###> symfony/framework-bundle ###
    - /.env
    + /.env.local
    + /.env.local.php
    + /.env.*.local
    
      # ...
  4. Rename .env to .env.local and .env.dist to .env:

    1
    2
    3
    4
    5
    6
    7
    # Unix
    $ mv .env .env.local
    $ git mv .env.dist .env
    
    # Windows
    C:\> move .env .env.local
    C:\> git mv .env.dist .env

    You can also update the comment on the top of .env to reflect the new changes.

  5. If you're using PHPUnit, you will also need to create a new .env.test file and update your phpunit.xml.dist file so it loads the tests/bootstrap.php file.
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
We stand with Ukraine.
Version:

Symfony 5.3 is backed by

Online exam, become Symfony certified today

Online exam, become Symfony certified today

Measure & Improve Symfony Code Performance

Measure & Improve Symfony Code Performance

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Brad Jones, a Symfony contributor

Thanks Brad Jones for being a Symfony contributor

3 commits • 5 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia