Drupal

Running Drush with an alternate version of PHP

Running Drush with an alternate version of PHP

I run PHP 7 by default on my laptop. For new projects, I typically use Symfony or Drupal 8, and launch the built-in servers with bin/console server:run or drupal server respectively.

For legacy sites that require PHP 5, I have PHP installed in /usr/local/php56/bin and use nginx w/php-fpm to serve them. For these sites, I need to run drush under PHP 5, but PHP 7 is setup as default via the command line.

My solution for this is pretty simple, create an alias named drush5.

I'm running Fedora on my development system, but this should work for other flavors, as well as OS X. On my system, PHP 5 and composer are installed in the following places.

Simply add the following alias to your .bash_profile, .bashrc or the appropriate file on your system. (Of course, replace the PHP5 and DRUSH paths as they apply to your system as well)

PHP5='/usr/local/php56/bin/php' 
DRUSH='/home/ekon/.config/composer/vendor/bin/drush' 
alias drush5='DRUSH_PHP=$PHP5 $DRUSH'

Make sure to run source ~/.bash_profile, or restart your terminal, and now you can use drush5 to run Drush with PHP 5.

Up Next

Ready To Get Started?

Schedule a complimentary 30-minute strategy consultation with one of our Drupal experts as early as today. We promise...they don't bite!