3

On my server there are two versions of PHP: 5.4 and 5.6. Using the shell PHP 5.4 is the standard and it can't be changed because of PLESK/ODIN. The websites I'm administering are using PHP 5.6 via PLESK, so Drupal 8 works fine. Drush doesn't, because it uses the shell.

I have installed Drush with the following commands:

php drush.phar core-status
mv drush.phar /usr/local/bin/drush
drush init

How can I change this to use PHP 5.6 in /opt/plesk/5.6?

2
  • drush up drupal works great for me
    – Clive
    Commented Jan 13, 2016 at 13:23
  • Looks like the PHP version that drush uses is too old?
    – Berdir
    Commented Jan 13, 2016 at 14:17

2 Answers 2

3

Drush has an environment variable DRUSH_PHP to set the php executable. You can set it in your .bashrc or directly on the command line:

env DRUSH_PHP=/opt/plesk/5.6/php drush status
2

Unless I'm missing something, what you need to do is, for your local shell, to have the system use the php5.6 executable rather than the php 5.4 one?

You need to find (or install) the php you need: for example, say the 5.4 version is in /usr/bin/php; the later one might be in /usr/local/bin/php

If you can't do that, you may be able to install your own version of php in your home directory (i.e. under /home/joeby/php/... ) though that is unfortunately not as simple as it might be.

Once you've located the correct php executable, do one of two things:

1) [This is the preferred solution:] Modify your shell PATH: e.g. in .bashrc a line like:

PATH=/usr/local/bin:${PATH}

where the /usr/local/bin is the folder you found the correct php in. It matters that this precedes the ${PATH}. Because the system searches for the php binary in the path, and you have only changed the path for your own shell (not for the system), it should mean you run the php you want, but the system sees the version it wants.

2) modify the drush php file. To do this you'd need to install drush as separate files, rather than a .phar file, and then find the file 'drush' and replace the first line. Normally it should look like this:

#!/usr/bin/env php

you can change it to:

#!/usr/local/bin/php

that is, the complete pathname of the executable you want to use. Once this is done remove write permission for yourself, so it is non-trivial for an update to replace the modified file:

chmod a-w /usr/local/bin/php

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.