Deployer: Deployer is generating an empty .env on the server during a deployment of a Symfony application.

Created on 17 Sep 2018  路  15Comments  路  Source: deployphp/deployer

| Q | A
| ----------------- | ---
| Issue Type | Bug
| Deployer Version | 6.3
| Local Machine OS | Xubuntu 18.04 LTS
| Remote Machine OS | Ubuntu 16.04 LTS

Description

I'm using the deployer.phar file to run the deploy, but the .env file generated by Deployer on the server is always empty.

Steps to reproduce

php deployer.phar deploy

Content of deploy.php

<?php
namespace Deployer;
require 'recipe/symfony.php';

// Configuration
host('production')
    ->set('branch', 'production')
    ->hostname('address.foo.bar')
    ->user('admin')    
    ->identityFile('~/path/to/pem/file')
    ->set('deploy_path', '/var/www/website')
;

set('repository', '[email protected]:team/repo');

set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');

set('ssh_type', 'native');
set('ssh_multiplexing', true);
set('http_user', 'www-data');
set('symfony_env', 'prod');

set('shared_files', [
    '.env',  
]);

set('shared_dirs', [
    'var/logs', 
    'var/sessions', 
    'app/spool'
]);

set('writable_dirs', [
    'var/cache', 
    'var/logs', 
    'var/sessions', 
    'app/spool'
]);

set('clear_paths', [
    'web/app_*.php', 
    'web/config.php'
]);

set('assets', ['web/css', 'web/images', 'web/js']);

set('dump_assets', false);

set('env', [
    'SYMFONY_ENV' => get('symfony_env'),
]);

set('bin_dir', 'bin');
set('var_dir', 'app');
// Servers

set('keep_releases', 5);


set('bin/console', function () {
    return sprintf('{{release_path}}/%s/console', trim(get('bin_dir'), '/'));
});

set('console_options', function () {
    $options = '--no-interaction --env=' . get('symfony_env');
    return get('env') !== 'prod' ? $options : sprintf('%s --no-debug', $options);
});

task('deploy:assetic:dump', function (){
    cd('{{current_path}}');
    run('{{env_vars}} {{bin/php}} {{bin/console}} assetic:dump {{console_options}}');
});

task('deploy', [
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'deploy:update_code',
    'deploy:clear_paths',
    'deploy:create_cache_dir',    
    'deploy:assets',
    'deploy:vendors',
    'deploy:shared',
    'database:migrate',
    'deploy:cache:warmup',
    'deploy:assets:install',
    'deploy:assetic:dump',
    'deploy:writable',
    'deploy:symlink',
    'deploy:unlock',
    'cleanup',
])->desc('Deploy your project');

after('deploy', 'success');

after('deploy:failed', 'deploy:unlock');


If i'm missing some info, please let me know.

Most helpful comment

I removed everything from my server ( release, releases and shared folders ) and installed again, now it's working, but now i'm getting a symfony error which says that it can't find a variable from .env but i think this is another problem. Thank you.

All 15 comments

Yes, you need to setup .env file by yourself in shared folder. Deployer can't know you server's credentials.

Nice, thank you, but doesn't Deployer have access to the shared folder anyway?

It has.

Ok, so the Deployer doesn't copy the content of the files? Thank you.

ho! i see what you mean. I was saying that Deployer is not copying the .env file content from my local machine to the server. I wasn't trying to say that Deployer is not generating the .env file content by itself.

I tried to make a .env file with my credentials on shared/.env but now Deployer is not even creating the .env file on the release path.

Add it to your shared_files config. Like add('shared_files', '.env');

I tried to do:

add('shared_files', '.env');

But got the following error:

[TypeError] Argument 2 passed to Deployer\Support\array_merge_alternate() must be of the type array, string given,
             called in phar:///Users/tres/Repositories/fechou-web/deployer6.3.phar/src/Deployer.php on line 212

Then i tried:

add('shared_files', [ '.env' ]);

But it didn't work, it is executing the deploy but not copying the file from the shared_files folder. Thank you for your effort.

Please, show full deploy.php

It looks almost the same from the deploy.php i posted on my first comment. Here is how my deploy.php looks like at the moment:

<?php
namespace Deployer;
require 'recipe/symfony.php';

// Configuration
host('production')
    ->set('branch', 'production')
    ->hostname('address.foo.bar')
    ->user('website')    
    ->identityFile('~/path/to/pem/file')
    ->set('deploy_path', '/var/www/website')
;

set('repository', '[email protected]:team/repo');

set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');

set('ssh_type', 'native');
set('ssh_multiplexing', true);
set('http_user', 'www-data');
set('symfony_env', 'prod');

add('shared_files',[
    '.env'
]);

set('shared_dirs', [
    'var/logs', 
    'var/sessions', 
    'app/spool'
]);

set('writable_dirs', [
    'var/cache', 
    'var/logs', 
    'var/sessions', 
    'app/spool'
]);

set('clear_paths', [
    'web/app_*.php', 
    'web/config.php'
]);

set('assets', ['web/css', 'web/images', 'web/js']);

set('dump_assets', false);

set('env', [
    'SYMFONY_ENV' => get('symfony_env'),
]);

set('bin_dir', 'bin');
set('var_dir', 'app');
// Servers

set('keep_releases', 5);


set('bin/console', function () {
    return sprintf('{{release_path}}/%s/console', trim(get('bin_dir'), '/'));
});

set('console_options', function () {
    $options = '--no-interaction --env=' . get('symfony_env');
    return get('env') !== 'prod' ? $options : sprintf('%s --no-debug', $options);
});

task('deploy:assetic:dump', function (){
    cd('{{current_path}}');
    run('{{env_vars}} {{bin/php}} {{bin/console}} assetic:dump {{console_options}}');
});

task('deploy', [
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'deploy:update_code',
    'deploy:clear_paths',
    'deploy:create_cache_dir',    
    'deploy:assets',
    'deploy:vendors',
    'deploy:shared',
    'database:migrate',
    'deploy:cache:warmup',
    'deploy:assets:install',
    'deploy:assetic:dump',
    'deploy:writable',
    'deploy:symlink',
    'deploy:unlock',
    'cleanup',
])->desc('Deploy your project');

// Display success message on completion
after('deploy', 'success');

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.

Hmmm, can't tell why. Works for me. Need to info, or reproducable case

Have you created a new symfony 3.3 app, made deploy and in the release folder there is a .env file with the correct info ? If yes, could you please send me your entire project?

Will send you later.

I removed everything from my server ( release, releases and shared folders ) and installed again, now it's working, but now i'm getting a symfony error which says that it can't find a variable from .env but i think this is another problem. Thank you.

I removed everything from my server ( release, releases and shared folders ) and installed again, now it's working, but now i'm getting a symfony error which says that it can't find a variable from .env but i think this is another problem. Thank you.

@matheusdallrosa did you manage to figure it out?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ElForastero picture ElForastero  路  3Comments

minkbear picture minkbear  路  4Comments

khoanguyen96 picture khoanguyen96  路  5Comments

greatwitenorth picture greatwitenorth  路  4Comments

osbulbul picture osbulbul  路  3Comments