Getting Composer and Drush to work on cPanel/WHM v58 with EasyApache 4

I was working on upgrading a full server running cPanel/WHM with EasyApache 4. This went smoothly as it was mostly an automated process after selecting a few options in WHM. The new cPanel/WHM version 58 has introduce some really nice new features, such as AutoSSL which allows for free SSL cert to be issued and use from Let's Encrypt.  

EasyApache 4 now offers multiple PHP versions, this means you can select and run a different PHP version per website domain. This is great as it means you can test your old and new development or production sites running different PHP version without having to switch PHP each time and restart your server or run multiple servers with different PHP version. But it can also be the source of the problem for installing certain server or command line  apps.

When you have a single PHP version, it was easy enough to know where it is located in the default directory structure. Now that we have multiple versions all installed in it's own directories, Composer and Drush needs to know where php resides.

The other problem is that i was using FastCGI (php-cgi) PHP handler which Composer and Drush will not work with since they only work with php-cli. 

These are the error messages in the error_log txt file:

[25-Aug-2016 01:11:22 UTC] PHP Warning:  Invalid argument supplied for foreach() in phar:///usr/local/bin/drush/includes/startup.inc on line 182

[25-Aug-2016 01:11:22 UTC] PHP Warning:  pcntl_exec() expects parameter 2 to be array, null given in phar:///usr/local/bin/drush/includes/startup.inc on line 355

[25-Aug-2016 01:11:22 UTC] PHP Warning:  fwrite() expects parameter 1 to be resource, string given in phar:///usr/local/bin/drush/includes/startup.inc on line 359

[25-Aug-2016 01:27:04 UTC] PHP Warning:  array_shift() expects parameter 1 to be array, null given in phar:///usr/local/bin/drush/includes/startup.inc on line 171

[25-Aug-2016 02:13:47 UTC] PHP Notice:  Undefined index: argv in phar:///usr/local/bin/composer/vendor/symfony/console/Input/ArgvInput.php on line 55

[25-Aug-2016 02:13:47 UTC] PHP Warning:  array_shift() expects parameter 1 to be array, null given in phar:///usr/local/bin/composer/vendor/symfony/console/Input/ArgvInput.php on line 59

[25-Aug-2016 02:14:16 UTC] PHP Warning:  Invalid argument supplied for foreach() in phar:///usr/local/bin/composer/vendor/symfony/console/Input/ArgvInput.php on line 276

[25-Aug-2016 04:04:06 UTC] PHP Warning:  Invalid argument supplied for foreach() in phar:///usr/local/bin/drush/includes/startup.inc on line 182

I knew the path to php-cli is /opt/cpanel/ea-php*/root/usr/bin/php so i needed to point and tell Composer and Drush where to locate php-cli to execute. At this point, i had a choice whether to use PHP7 or PHP5.6 version. I chose 5.6 for stability.

The fix was to add the couple of lines below into ~/.bash_profile file:

alias composer='/opt/cpanel/ea-php56/root/usr/bin/php /usr/local/bin/composer'

alias drush='/opt/cpanel/ea-php56/root/usr/bin/php /root/.composer/vendor/bin/drush'

Then run source ~/.bash_profile

That's it, problem solved.

 

Drush Image was taken from Dijup Tuladhar website.

The content of this field is kept private and will not be shown publicly.
Your email address will be kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.