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_profile
files
touch ~/.bashrc ~/.bash_profile
ShellScriptOpen the ~/.bash_profile
file with nano
, vim
or your favorite editor and add the following
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
ShellScriptSetup 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'
ShellScriptIf you want to use a custom
php.ini
file for thephp
command and not the global one you can create the file in your home directory and use it in the alias likealias 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
ShellScriptMake it excecutable
chmod +x wp-cli.phar
ShellScriptAdd 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'
ShellScriptTest it
You will need to log out and log in again to test the changes.
php -v && wp cli version
ShellScript