Verdant TCS

Setting the CLI PHP Version

2 min read

Out of the box, our default CLI PHP setting is 7.3, soon to be updated to 7.4 out of the box. However, on some older servers, this may still be set to the default of PHP 7.2.

Some programs (such as Composer for example) require a higher version of CLI than the default 7.2 version which may require you to update this to a higher version.

Here’s an example of this error from a site where SSO was failing to generate a login link:

Your Composer dependencies require a PHP version “>= 7.3.0”. You are running 7.2.25-1+ubuntu18.04.1+deb.sury.org+1. Error Code: 100 | PHP Errors stopping SSO Link creation, please check logs….

Here Composer is using the CLI PHP version, and not the FPM one that is used by sites. Switching the PHP version of your sites will not fix this specific issue as this only changes the PHP version for FPM.

This is a quick and easy fix though. 

Updating the CLI PHP Version

To run this update you will need to SSH into your server. Please see the following guides to get started:

Step 1. Generate your SSH Key

Step 2. Add your SSH Key to vCanopy (also see Add default SSH Keys)

Step 3. Connect to your server by SSH as Root user (we like and use Termius)

Checking your CLI PHP Version

To check your CLI PHP version, you can run the following command:

sudo update-alternatives --display php

This will output the following, only with the correct PHP version should your setting be different:

root@servername:~# sudo update-alternatives --display php
php - auto mode
link best version is /usr/bin/php7.3
link currently points to /usr/bin/php7.3
link php is /usr/bin/php
slave php.1.gz is /usr/share/man/man1/php.1.gz
/usr/bin/php7.3 - priority 73
slave php.1.gz: /usr/share/man/man1/php7.3.1.gz
root@servername:~#

Changing your CLI PHP Version on Nginx

Run the following command to change the CLI version:

sudo update-alternatives --set php /usr/bin/php7.X

X = the version number, which could be 1,2,3,4.

For example: 

sudo update-alternatives --set php /usr/bin/php7.4

Changing your CLI PHP Version on OpenLiteSpeed

Changing the CLI PHP version on OLS is a 2 step process.

STEP 1. INSTALL THE PHP VERSION

First, you need to install the specific PHP version you wish to use with:

sudo update-alternatives --install /usr/bin/php php /usr/local/lsws/lsphp7X/bin/php 80

X = the version number, which could be 2,3,4.

For example:

sudo update-alternatives --install /usr/bin/php php /usr/local/lsws/lsphp74/bin/php 80

STEP 2. MAKE THE CHANGE

Next, run the following command to change the CLI version:

sudo update-alternatives --set php /usr/local/lsws/lsphp7X/bin/php

Again, X = the version number, which could be 2,3,4.

For example:

 sudo update-alternatives --set php /usr/local/lsws/lsphp74/bin/php

Once done, you’re all set! 

Search the Knowledge Base

New to vCanopy?

Get started with our FREE Core plan today! We bring the software, you bring the hardware.