If you have added SSH access to your Plesk user using the following tutorial "How to enable SSH on the Plesk domain user" and then tried to run the PHP command:
# php -v
You might have come across the following errors:
-bash: php: command not found
/usr/bin/env: 'php': Permission denied
This happens because Plesk does not store the PHP binary in the locations defined in the PATH environment variables. You can check the existing environment variables with this command:
# echo $PATH
/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
Plesk stores the PHP binaries for different versions at this path: /opt/plesk/php/.
For example, if you are trying to use the PHP 7.4 binary, it would be done as follows:
# /opt/plesk/php/7.4/bin/php -v
PHP 7.4.10 (cli) (built: Sep 4 2019 04:29:34) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.4.2, Copyright (c) 2002-2019, by ionCube Ltd.
with Zend OPcache v7.4.10, Copyright (c), by Zend Technologies
So, to be able to use php -v directly, you need to add this binary path to your PATH environment variable. You can do this by running the following command:
# PATH=$PATH:/opt/plesk/php/7.4/bin/
Now you can run the following command, and it will work:
# php -v
PHP 7.4.10 (cli) (built: Sep 4 2019 04:29:34) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.4.2, Copyright (c) 2002-2019, by ionCube Ltd.
with Zend OPcache v7.4.10, Copyright (c), by Zend Technologies
It is important to remember that this will only be valid for the current session. If you log out and log back in, this change will be lost. To make it permanent for every login session, you need to add it to the .profile file. You can do this by running the following command:
# echo "PATH=$PATH:/opt/plesk/php/7.4/bin/" >> .profile
Once this is done, you can log out, log back in, and check that php -v still works:
[user-plesk@plesk_server ~]$ exit
logout
[root@plesk_server ~]# su - user-plesk
Last login: Thu Oct 1 13:42:13 IST 2020 on pts/0
[user-plesk@plesk_server ~]$ php -v
PHP 7.4.10 (cli) (built: Sep 4 2019 04:29:34) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.4.2, Copyright (c) 2002-2019, by ionCube Ltd.
with Zend OPcache v7.4.10, Copyright (c), by Zend Technologies
[user-plesk@plesk_server ~]$
We hope this tutorial has been helpful 🙂. Remember, if you have any questions about this or any other issue related to your servers on Clouding, feel free to write to soporte@clouding.io. We’re here to help with whatever you need!