Skip to content
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

.env problem #87

Open
wcizmowski opened this issue Jan 29, 2019 · 13 comments
Open

.env problem #87

wcizmowski opened this issue Jan 29, 2019 · 13 comments

Comments

@wcizmowski
Copy link

Hi,

I have
$this->runRemote('export SYMFONY_ENV=prod');

but uppon deploy error

PHP Fatal error: Uncaught Symfony\Component\Dotenv\Exception\PathException: Unable to read the "/var/www/vhosts/iwebi.pl/app-s4.iwebi.pl/releases/20190129153613/.env" environment file. in /var/www/vhosts/iwebi.pl/app-s4.iwebi.pl/releases/20190129153613/vendor/symfony/dotenv/Dotenv.php:466

butr

@kunno
Copy link

kunno commented Jan 31, 2019

In src/Deployer/DefaultDeployer.php:264 change $this->runRemote(sprintf('cp -RPp {{ deploy_dir }}/repo/* {{ project_dir }}')); to $this->runRemote(sprintf('cp -RPp {{ deploy_dir }}/repo/. {{ project_dir }}')); this will 'cp' all files including the hidden .env. Hope that helps. If you are using Symfony 4.2, there might be some more steps to do. Just comment if you run into any other issues.

Also, since you're deploying to prod you should move composer require symfony/dotenv from require-dev to require in your composer.json

@ghost
Copy link

ghost commented Feb 17, 2019

I confirm that changing /repo/* to /repo/. works for Symfony 4.2.

Neofox added a commit to Neofox/camie that referenced this issue Feb 19, 2019
@daum
Copy link

daum commented Mar 7, 2019

I've hit this problem too. A note is by doing the change in the repo copy it's going to copy the full .git directory over too. Instead since often you don't want all your dotfiles copied it'd be better to use beforePreparing:

    public function beforePreparing()
    {
        $this->log('<h3>Copying over the .env files</>');
        $this->runRemote('cp {{ deploy_dir }}/repo/.env {{ project_dir }}');
    }

@stloc
Copy link

stloc commented Mar 18, 2019

the /release directory doesn't contain .env file while /repo dir has this .env file

@gustawdaniel
Copy link

gustawdaniel commented Apr 8, 2019

Could I please describe this issue in documentation? I confused about best practices of managing .env when I using this bundle.

I was trying

    // run some local or remote commands before the deployment is started
    public function beforeStartingDeploy()
    {
         $this
             ->runLocal('./vendor/bin/simple-phpunit --env=dev');
    }

and

    // run some local or remote commands before the deployment is started
    public function beforeStartingDeploy()
    {
         $this
             ->symfonyEnvironment('dev')
             ->runLocal('./vendor/bin/simple-phpunit');
    }

But both does not works. In case of default config

    public function beforeStartingDeploy()
    {
         $this
             ->runLocal('./vendor/bin/simple-phpunit');
    }

I obtaining

The command "(export APP_ENV=prod; cd /home/daniel/pro/pregnacore/core && ./vendor/bin/simple-ph  
  punit --env=dev)" failed. 

Because of APP_ENV should be dev not prod locally during testing. Because I have test in dev requirements.

@prograamer
Copy link

prograamer commented May 8, 2019

This works for me.

public function **beforeUpdating**() { $this->runRemote('cp {{ deploy_dir }}/repo/.env {{ project_dir }}'); parent::beforeUpdating(); }

@nitrique
Copy link

Hi,

On my side I prefer :

public function beforePreparing() { $this->log('<h3>Copying over the .env files</>'); $this->runRemote('cp {{ deploy_dir }}/repo/.env.dist {{ project_dir }}/.env'); }

@ghost
Copy link

ghost commented Jul 17, 2019 via email

@nitrique
Copy link

nitrique commented Jul 17, 2019

The deploy script don't seems to copy dot files on project root folder, is that only for me ?

@kaizokou
Copy link

I also faced this issue.
As a workaround, I put the .env and .env.local file as shared file.
->sharedFilesAndDirs(['.env','.env.local'])

The drawback is that you now have to handle manually the change in your .env file as it won't be synchronized with your repo, but anyway you would have to edit your .env.local file. No big deal.

@COil
Copy link

COil commented Nov 30, 2019

Hello, I have also to put the .env as a shared file. Check out https://stackoverflow.com/q/59111354/633864, in fact I don't need to use env vars as my application only relies on .env files. Do you think I would be ok to introduce a new parameter to see if the APP_ENV env should be set?

numediaweb added a commit to numediaweb/easy-deploy-bundle that referenced this issue May 31, 2020
This fixes issues like EasyCorp#87
```
Unable to read the "... .env" environment file. in ...
```
@numediaweb
Copy link

numediaweb commented May 31, 2020

Using Symfony 5 with PHP 7.4, this PR #114 fixes that issue.

@fd6130
Copy link

fd6130 commented Jan 15, 2021

I thought we shouldn't commit any secrets in .env ? If that the case we have to manual copy paste our .env.local.php each time we deploy and not relying on the .env from git.

numediaweb added a commit to numediaweb/easy-deploy-bundle that referenced this issue Oct 9, 2023
This fixes issues like EasyCorp#87
```
Unable to read the "... .env" environment file. in ...
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests