Skip to content
Advertisement

APP_SERVER env var not found when deploying with EasyDeploy

I have this error when the deploy script tries to install the assets:

(Setup PHP 7.2, Symfony 4.4)

[SymfonyComponentProcessExceptionProcessFailedException]
The command "ssh -A root@vps.net -p 21 '(export APP_ENV=prod; cd /var/www-deploy/site.com/releases/20191129224025
&& php /var/www-deploy/site.com/releases/20191129224025/bin/console assets:install /var/www-deploy/site.com/releases/20191129224025/public --symlink --no-debug --env=prod)'" failed.
Exit Code: 1(General error)
Working directory: /Users/coil/Sites/site.com
Output:
================
Error Output:
================
In EnvVarProcessor.php line 162:
Environment variable not found: "APP_SERVER".

I have put the .env file in the shared files, so it’s copied when the release directory is created, this file is in the directory.

public function configure(): DefaultConfiguration
{
    return $this->getConfigBuilder()
        // ...
        ->sharedFilesAndDirs(['.env'])
        // ...
}

I also tried to put the env vars in the .bashrc file of the user who deploys:

printenv | grep -i app
APP_DEBUG=0
APP_SECRET=whatever
APP_ENV=prod
APP_SERVER=prod

So, I don’t understand, why the environment variables are still not found. And why they are not taken from the .env file. If I interrupt the deployment and if I manually run the same command on the server it works well. Thanks.

[Edit 2019-11-30] I think I understand know, when running the command, there is an export of the APP_ENV that is done. And, if the application detects this env variable it will just skip the .env file. So, I need to avoid setting this env var, or I must set all instead of this one only.

Advertisement

Answer

[Edit 2021-02-13] I have fixed the bin/console file and removed the “hack”. Instead of testing the APP_ENV var I test the APP_SECRET one which is not set by EasyDebug:

if (!isset($_SERVER['APP_SECRET'])) {
    (new Dotenv())->load(__DIR__.'/../.env');
}

Old solution:

It now works with the following modififications, in src/Configuration/DefaultConfiguration.php:

} elseif (4 === $symfonyMajorVersion || (3 === $symfonyMajorVersion && 4 >= $symfonyMinorVersion)) {
    $this->_symfonyEnvironmentEnvVarName = 'APP_ENV';

I have passed an unkown env var to Symfony:

$this->_symfonyEnvironmentEnvVarName = 'APP_FAKE_ENV';

So the .env file is not ignored any-more. I think there is a missing option to set or not this environment var based on the setup of the application. I’ll try to do a PR to the bundle.

So, as the bundle is not modified yet, I have modified the private property, in order to make the command use my .env files instead of environment variables:

/**
 * @see https://stackoverflow.com/q/1762135/633864
 */
private function forceEnvironmentEnvVarName(DefaultConfiguration $configuration): DefaultConfiguration
{
    $myClassReflection = new ReflectionClass(get_class($configuration));
    $symfonyEnvironmentEnvVarName = $myClassReflection->getProperty('_symfonyEnvironmentEnvVarName');
    $symfonyEnvironmentEnvVarName->setAccessible(true);
    $symfonyEnvironmentEnvVarName->setValue($configuration, 'FAKE_APP_ENV');
    $symfonyEnvironmentEnvVarName->setAccessible(false);

    return $configuration;
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement