Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Deployer to use different PHP version once ssh'ed to my shared hosting?

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', '[email protected]: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');
like image 485
Matt Komarnicki Avatar asked Mar 01 '18 12:03

Matt Komarnicki


People also ask

Can I run several versions of PHP at the same time?

Similarly, PHP-FPM uses a daemon to manage multiple PHP versions on a single instance. Together, you can use Apache and PHP-FPM to host multiple PHP web-applications, each using a different version of PHP, all on the same server, and all at the same time.


1 Answers

OK, I've found the solution.

I added (after require):

set('bin/php', function () {
    return '/usr/local/bin/php70';
});
like image 200
Matt Komarnicki Avatar answered Oct 03 '22 08:10

Matt Komarnicki