Setup a Specific PHP CLI Version and WP-CLI for a Shared SSH User in Plesk

You will need your account’s SSH user to have /bin/bash access for the following setup. Consult with your shared hosting provider and make sure that your SSH user has /bin/bash access.

If you have administrator access to the server you can enable SSH access for an account if you go to Domains > example.com > Web Hosting Access and set option Access to the server over SSH to /bin/bash > OK to apply the changes.

SSH to the server with the username and the password of your account’s system user (primary FTP user) and perform the following steps.

Create the necessary files in your home directory if they are not present.

Create the ~/.bashrc and ~/.bash_profilefiles

touch ~/.bashrc ~/.bash_profile
ShellScript

Open the ~/.bash_profile file with nano, vim or your favorite editor and add the following

if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
ShellScript

Setup the desired PHP version

Plesk is using the pattern /opt/plesk/php/X.X/bin/php for storing the PHP binary paths. So, we will need to adjust the PHP version and create an alias for the php command in our ~/.bashrc file.

Open the ~/.bashrc file and add the following

alias php='/opt/plesk/php/7.4/bin/php'
ShellScript

If you want to use a custom php.ini file for the php command and not the global one you can create the file in your home directory and use it in the alias like alias php='/opt/plesk/php/7.4/bin/php -c ~/custom_php.ini

Download and setup WP-CLI

Download WP-CLI to your home directory

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
ShellScript

Make it excecutable

chmod +x wp-cli.phar
ShellScript

Add the alias for the wp command in your ~/.bashrc file, you can adjust the PHP version as you wish

alias wp='/opt/plesk/php/7.4/bin/php ~/wp-cli.phar'
ShellScript

Test it

You will need to log out and log in again to test the changes.

php -v && wp cli version
ShellScript