Here’s a scenario:
The hosting provider’s Apache server is using the PHP version specified by the control panel, via the web interface. It’s set to 8.1. However, the PHP version used by SSH (for my Linux user) is still using PHP 7.1.
This causes issues when relying on Composer or Drush via SSH.
I want to specify the PHP version used by the SSH manually. We can do it by overriding the default alias of the bash command.
First, we will need to locate the .bashrc file. This will vary on the hosting provider. In my case, it’s:
/home/[user name]./bashrc
/home/pawel./bashrc
Now, let’s edit the .bashrc file. I want to specify the PHP version to 8.1. We can specify it by editing the alias for Drush, PHP and Composer. This way we can specify and tell the Bash shell command to run a specified code.
alias php='/usr/local/bin/php81'
Log out and log in via SSH again. Check the PHP version, it should be updated.
php -v
We can also override the “drush” and “composer” commands to use PHP 8.1.
alias php='/usr/local/bin/php81'
alias drush='/usr/local/bin/php81 -d memory_limit=2048M [directory path]/public_html/[project name]/vendor/drush/drush/drush.php'
alias composer='/usr/local/bin/php81 -d memory_limit=4096M /usr/local/bin/composer.phar'
Note that for Drush, I’m pointing to the codebase within my project.