9

I'm experimenting with Deployer to deploy Laravel application into shared hosting (using laravel recipe) from my local ~/Code/project_foo.

The point is that when I'm connected to my shared hosting server via ssh, then default php -v version is 5.6.33. I confirmed that I can change php version on fly by calling php70 -v or even whole path like /usr/local/bin/php70 whatever.

The point is that I don't know how to tell deployer to call commands using php70 which is required, otherwise composer install fails.

enter image description here

So in Terminal I'm inside root of the Laravel project and I simply call:

dep deploy

My deploy.php is messy and very simple but this is just a proof of concept. I'm trying to figure out everything and then I will make it look nicer.

enter image description here

I checked the source code of the laravel recipe, and I saw that there is:

{{bin/php}}

but I don't know how to override the value to match what my hosting tells me to use:

/usr/local/bin/php70

Please, give me any hints how to force the script use different PHP version once connected to the remote host / server.

This is whole script:

<?php
namespace Deployer;

require 'recipe/laravel.php';


//env('bin/php', '/usr/local/bin/php70'); // <- I thought that this will work but it doesn't change anything


// Project name
set('application', 'my_project');

// Project repository
set('repository', 'git@github.com:xxx/xxx.git');

// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true); 

// Shared files/dirs between deploys 
add('shared_files', []);
add('shared_dirs', []);

// Writable dirs by web server 
add('writable_dirs', []);


// Hosts

host('xxx')
    ->user('xxx')
    ->set('deploy_path', '/home/slickpl/projects/xxx');

// Tasks

task('build', function () {
    run('cd {{release_path}} && build');
});

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

// Migrate database before symlink new release.

before('deploy:symlink', 'artisan:migrate');
Matt Komarnicki
  • 5,198
  • 7
  • 40
  • 92

4 Answers4

25

OK, I've found the solution.

I added (after require):

set('bin/php', function () {
    return '/usr/local/bin/php70';
});
Matt Komarnicki
  • 5,198
  • 7
  • 40
  • 92
  • Hi Matt, what do you mean `after require` - I am having the same issue I tried to set php path right after the `require 'recipe/laravel.php'` (not sure if that is what you mean by require) wihout any luck. `set('bin/php', function () { return '/var/www/my-user/data/bin/php';})` – Raja Khoury Apr 01 '20 at 17:30
  • This is exactly what I meant. Put it after the 4th line (`require 'recipe/laravel.php';`). – Matt Komarnicki Apr 01 '20 at 18:04
  • 1
    This was working but the problem wasn't in the config but the shell ouput for example my task `php_ver` outputs 5.6 on the other hand the deployer script is using the correct php version (7.3) - not sure why ( logging in as the user itself as well..) Anyways thanks for the reply Matt. Cheers. – Raja Khoury Apr 01 '20 at 18:34
13

For anybody who searches for changing Composer's PHP version:

set('bin/composer', function () {
    return '/usr/bin/php7.4 /usr/local/bin/composer';
});
Michael Käfer
  • 1,597
  • 2
  • 19
  • 37
1

There is function locateBinaryPath() so result is:

set('bin/php', function () {
    return locateBinaryPath('php7.4');
});
0

first found php path and composer path use this for more information Setting PHP versions in Deployer deployments

find / -type f -name "php"   2>&1 | grep -v "Permission denied"

find / -type f -name "composer"   2>&1 | grep -v "Permission denied"

then

set('bin/composer',
function () {
    return 'php_path composer_path';
});

like this

set('bin/composer',
function () {
    return '/opt/remi/php73/root/usr/bin/php /usr/bin/composer';
});
moez sabri
  • 1
  • 1
  • 1