Matching the PHP version in the Dashboard to the version used by the SSH Command Line Interface. (CLI)

There are several versions of PHP installed on the oCIO Webhosting Platform. This document will help you set the PHP version used by Apache and match it to the version used by the SSH Command Line Interface. (CLI)

First, determine which version of PHP best suits your website, and set it in the Webhosting dashboard at https://web.osu.edu. It’s best practice to use the latest stable version, but you may have reasons for staying on an older version. Either way, set the PHP version under ‘Server Options’ in the Dashboard and give it about an hour to propagate through all the Web Nodes.

image-2722

Now let’s SSH into webssh.osu.edu and setup the CLI version of PHP. 

Log into the Webhosting Shell for your site and enter the following command:  

export PATH=”/usr/local/php/[version]/bin:$PATH”   

Replacing [version] with the version of PHP you chose earlier (5.6, 7.2, 7.4, etc.)  Then issue the command:  

cat ~/.bash_profile  

and copy the line that starts with “PATH= “

Now Open ~/.bashrc with your favorite Text Editor and paste that PATH line into the file, just above the line that reads # User specific aliases and functions”.  Save the changes and close the file.

Now let’s setup a few other aliases to make PHP run like we want. Enter the following commands, replacing [version] with the same version of PHP you used earlier.  Issue the command: 

echo alias php=”/usr/local/php/[version]/bin/php” >> ~/.bashrc 

And Then: 

source ~/.bashrc 

Now, when you enter the command:  

php version  

You should get the same version you chose in the webhosting Dashboard.  

Additionally, if you use composer, you’ll want to force the version of PHP it uses too.  Go to the directory containing your composer.json file and enter these three commands, in order, replacing [version] with the same version of PHP you used earlier: 

echo alias composer=”/usr/local/php/[version]/bin/php /usr/local/bin/composer” >> ~/.bashrc 

source ~/.bashrc 

composer config platform.php [version] 

This will set the platform option in the composer.json file for us. You can also use the -g flag to set this globally.