Setting the PHP version in command line on CPanel Servers

Setting the PHP version in command line on CPanel Servers

Over the last couple of days, I’ve been really struggling to try to get Composer to install a project on a CPanel server. As you know, Composer can also check environment constraints and for some reason¬†php -v would show PHP 7.1 but when running composer install or php composer install, it would say that I’m using PHP 5.6.

I tried using the full path to both PHP and Composer (to find that out, you can use which php and which composer) with no luck. After a bit of research, I finally found that EasyApache 4 (the system that manages Apache and PHP on CPanel servers) has the ability to pass an argument to the command allowing you to see the PHP version.

 /usr/bin/php -ea_php 56 filename.php

You can replace 56 with the specific version of PHP that you want like 70 for PHP 7.0.x or 71 for PHP 7.1.x. My new command looked like this:

php -ea_php 71 /opt/cpanel/composer/bin/composer install

It’s obviously important to run Composer with the version of PHP that your web server is running as it will install the dependencies with those constraints in mind.

Share

Hire WordPress exportsLoading comments...

Leave a comment

Your email address will not be published. Required fields are marked *