3

On the live server I use differents Drush and PHP versions for Drupal 8.4 and 7. I install Drush 9 to the ~/drush9 directory with composer require drush/drush:9.*.

On the development server and Drupal 8.4, I use the site.alias.yml file for Drush 9.

live:
  host: hostingexample.com
  user: user
  root: /home/user/example.com/public_html/
  uri: http://example.com/
  paths:
    drush-script: '/opt/php70/bin/php /home/user/drush9/vendor/bin/drush'

When I run drush @site.live ev 'print PHP_VERSION' I get this error.

bash: /opt/php70/bin/php /home/user/drush9/vendor/bin/drush: No such file or directory

If I add these lines in the .bash_profile file and change drush-script: '/home/user/drush9/vendor/bin/drush' in site.alias.yml, I get an error because the default PHP version is 5.3.

alias php=/opt/php70/bin/php
alias drush9=~/drush9/vendor/bin/drush

PHP Parse error: syntax error, unexpected '[' in /home/user/drush9/vendor/drush/drush/src/Config/Environment.php on line 98

How can I use a different PHP for the live server and set it for Drush 9 aliases?

1

2 Answers 2

1

Try editing both the .bash_rc and .bash_profile files so that you include the directory where the version of PHP you want is FIRST (before existing PATH):

(add this line or adjust if existing):

export PATH="/opt/php70/bin:$PATH"

As a last ditch effort, you can set the env variable drush looks for as well in these files:

DRUSH_PHP=/opt/php70/bin/php

1
  • The "export PATH=..." method worked for me; I set it in a bash script I use to automate deploys on a shared hosting account; the site runs Drupal 8.9, with Drush 9. Thanks!
    – Jedihe
    Commented Jul 13, 2020 at 1:44
1

From drush 10+ it is possible to set the PATH variable within self.site.yml, so the OP's situation would be resolved as follows:

live:
  host: hostingexample.com
  user: user
  root: /home/user/example.com/public_html/
  uri: http://example.com/
  paths:
    drush-script: '/home/user/drush9/vendor/bin/drush'
  env-vars:
    PATH: /opt/php70/bin/php:/bin:/usr/bin

N.B. I do not think this will work with drush 9 (but I'm happy to be proved otherwise)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.