Allow specifying the location of the .env file

Created on 12 July 2024, 5 months ago
Updated 23 August 2024, 4 months ago

In some cases it's not possible to place a .env file above the webroot. Symfony makes allowance for that as described here: https://symfony.com/doc/current/configuration/override_dir_structure.html.

But if I implement the composer-based solution they show, the Symfony dotenv dump winds up with two paths to .env, one of which can't be found because this plugin hardwires it with $container->setParameter('dotenv.project_dir', DRUPAL_ROOT . '/..'); . So drush dotenv:dump winds up failing.

I've fixed it for my own project with a simple patch file, but it might be useful to update this in a way that provides an argument, permitting a different project_dir.

If I roll that myself, I'll provide it here, but I also offer it as a question or request.

✨ Feature request
Status

Fixed

Version

1.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States datawench

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @datawench
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    At the moment this module doesn't have any config and I feel like this use case might be a bit too niche to justify introducing config. Why don't you create a custom module with a service provider where you set the dotenv.project_dir container parameter to a different value?

  • Status changed to Needs review 5 months ago
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    Or even easier, can’t you set the parameter in the services.yml file? If the service provider overrides that value, we could add a check to make sure to only set a project path if there isn’t any yet.

  • πŸ‡ΊπŸ‡ΈUnited States datawench

    Hm. I wouldn't have thought it was that niche? I should think it's pretty common to have .env inside webroot, due to the variety of hosting setups.

    But I can certainly create a service provider, as you suggest. If you provided a check as you describe, that would be great.

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    Looking at the source of the dotenv:dump command, it seems like project_dir should always be the Composer root of the project. Since we're already using DrupalFinder in the dotenv:init command, I decided to use this here as well to automatically determine the project_dir. Could you check if the changes in this MR fix the issue for you?

    I also made it so dotenv.project_dir can be set in services.yml, but this shouldn't be needed for you anymore. Setting dotenv_path in composer.json also shouldn't be needed anymore.

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    @datawench any chance you could check if the provided solution fixes the issue for you?

  • Pipeline finished with Skipped
    4 months ago
    #248755
  • Status changed to Fixed 4 months ago
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024