Applicable to:
- Plesk for Linux
Question
How to configure a specific command line PHP version for an SSH user on a Plesk for Linux server?
Answer
Note: To apply the solution described in this article it's required to connect to the server with the root user. If root access is not available via SSH, contact your hosting service provider.
By default, the php
command calls the binary installed by the PHP version provided by the operating system repository. The binary path of the php
command can be retrieved with the following command:
# which php
/usr/bin/php
Alternatively, it's possible to install other PHP versions from Plesk, and to execute those on the command line it's required to call the full binary path. For example:
# /opt/plesk/php/7.4/bin/php -v
PHP 7.4.11 (cli) (built: Oct 2 2020 14:09:37) ( NTS )
All binaries from the additional Plesk PHP versions installed on the server can be retrieved with the following command:
# find /opt/plesk/php/*/bin/php
To modify the PHP binary called by the php
command for a Plesk system user, apply one of the following options according to the SSH option configured on the subscription:
Click on a section to expand
-
Log in to Plesk GUI as Plesk Administrator
-
Go to Domains > example.com > Web Hosting Access and set option Access to the server over SSH to /bin/bash (chrooted) > OK to apply the changes
-
Connect to the server via SSH with the root user
-
Create a symlink with the relative path:
# ln -s /opt/plesk/php/7.4/bin/php /var/www/vhosts/chroot/bin/php
-
Apply chroot template to all the subscriptions:
# ./update_chroot.sh --apply all
-
Switch to the Plesk system user of the subscription:
# su example_user
-
Verify the PHP version running the following command:
# bash-4.2$ php -v
PHP 7.4.11 (cli) (built: Oct 2 2020 14:09:37) ( NTS )Note: If CageFS is enabled for user on CloudLinux OS, it is required to add PHP to CageFS instead
-
Log in to Plesk GUI as Plesk Administrator
-
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
-
Connect to the server via SSH with the root user
-
Switch to the Plesk system user of the subscription:
# su example_user
-
Add the PHP binary path on the
.bashrc
file:# echo "alias php='/opt/plesk/php/7.4/bin/php'" >> ~/.bashrc
* Where
/opt/plesk/php/7.4/bin/php
is the necessary PHP binary path -
Add the following content to the
.bash_profile
file:# echo "if [ -f ~/.bashrc ]; then" >> ~/.bash_profile
# echo ". ~/.bashrc" >> ~/.bash_profile
# echo "fi" >> ~/.bash_profile -
Log out to reload the changes:
# exit
-
Verify the PHP version running the following command:
# su example_user
# php -v
PHP 7.4.11 (cli) (built: Oct 2 2020 14:09:37) ( NTS )
Comments
2 comments
poor quality
hi Eamon DrTutor, could you please describe what part of the article has "poor quality". In that way we can improve it.
Please sign in to leave a comment.