php-deployer

PHP Deployer: How to get user name from host setup


I am trying to deploy my code via php deployer, but I am facing a syntax issue, which is how can I re-use the host user on task?

For instance, I would like to replace USERNAME with barfoo in dynamic way. Not hard code.

Can anyone give me a suggestion? Much appropriate.

host('17.99.88.225')
     ->user('barfoo') // This is the server user name
     ->stage('production')
     ->set('deploy_path', '/SERVER_PATH/{{application}}')
     ->set('branch', 'develop');

...

task('upload:env', function () {
      runLocally('scp .env USERNAME@{{hostname}}:{{release_path}}/.env');
})->desc('Environment setup');

Solution

  • I just figure it out myself. I would like to share here:

    All I need to do is set a new variable and use it on my script. LOL

    set('username', 'nanomed1'); // set my own variable
    ...
    task('upload:env', function () {
    
      $username = get( 'username');  // use the variable I created on the top
    
      runLocally('scp .env '.$username.'@{{hostname}}:{{release_path}}/.env');
    })->desc('Environment setup');
    

    That's it!