How to specify command line command "php" version for SSH user on the Plesk server?

Follow

Comments

14 comments

  • Avatar
    Jari Koivisto

    I tried to add .bashrc file with php alias line, but it didn't do the trick for me.

    I had to add PATH to .bash_profile file:

    echo "PATH=/opt/plesk/php/7.1/bin:$PATH" >> ~/.bash_profile

    Log out and log in. After that php -v show version 7.1.*

     

    4
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello @Jari, thank you for sharing your experience, it may be useful for other Pleskians.

    I have checked the instructions on a test server with CentOS 7 and Debian 9, the provided steps were sufficient. 

    1
    Comment actions Permalink
  • Avatar
    Unknown User

    Thanks Jari your solution helped!

    1
    Comment actions Permalink
  • Avatar
    Robert Perrett

    Didn't work for me, no matter what I tried (Centos 7).  Finally came across another post on stackexchange which did the trick.

    sudo env "PATH=/opt/plesk/php/7.2/bin:$PATH" wp-cli.....

    Yes I installed my own version of wp-cli because the one built in with plesk has issues with DB search/replace.

    0
    Comment actions Permalink
  • Avatar
    Erwan

    Hi all,

    I had a different version from the domaines>php settings and the ssh one. Thanks to your solution I have the same one now : 5.6 according to php -v.

    But when I run composer require league/oauth2-google to install oauth2, I get the following message:

    league/oauth2-client 2.4.1 requires php ^5.6|^7.0 -> your PHP version (5.5.9) does not satisfy that requirement.

    Do you have any clue? It seems that the version used by composer is another one.

    TIA.

    Erwan

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello @Erwan,

    Please, check the instructions in the following article https://support.plesk.com/hc/en-us/articles/115001707605 


    As an example of using composer, you may check our article on how to install Laravel https://support.plesk.com/hc/en-us/articles/360000399513 :

    # cd httpdocs/ && /opt/plesk/php/X.Y/bin/php /usr/lib64/plesk-9.0/composer.phar create-project laravel/laravel --prefer-dist

    0
    Comment actions Permalink
  • Avatar
    Jan Bludau

    solution for PHP 7.2

    echo "PATH=/opt/plesk/php/7.2/bin:$PATH" >> ~/.bash_profile

    0
    Comment actions Permalink
  • Avatar
    Alexandr Nikolaenko

    Hello @Jan Bludau,

    Thank you for the input. Such a way also takes place.

    Just for other Pleskians: do not forget to log out/login after "~/.bash_profile" file is edited.

    0
    Comment actions Permalink
  • Avatar
    Hüseyin Şevki TOPUZ (Edited )

    Hello, thank you for the article. It helped very much but did not solve my problem. I have changed default php version for a specific user for php command over SSH. But it does not change the version for scheduled tasks. On SSH, when i use php -v, i can see 7.2 but not in scheduled tasks. I am creating a cronjob but i am having error so i tried this command at scheduled tasks

    php -v >> httpdocs/logs/phplogs.log

    and the log file shows

    PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.0.3, Copyright (c) 2002-2017, by ionCube Ltd.

    How can i fix this? I want php 7.2 to become the default handler for scheduled tasks too.

    0
    Comment actions Permalink
  • Avatar
    Nikita Nikushkin

    Hello @Hüseyin Şevki TOPUZ,

    Shell spawned by Cron is not equal to the shell spawned by sshd

    Thus, it returns system PHP instead of Plesk PHP 7.2 you set up

    In scheduled tasks, you have to use the absolute paths, e.g. "/opt/plesk/php/7.2/bin/php -v"

    Check this article for details

    0
    Comment actions Permalink
  • Avatar
    Robert

    What would i need to do to define a alias for all ssh domain users or even better provide the .bashrc from root user?

    0
    Comment actions Permalink
  • Avatar
    Alexey Lapshin (Edited )

    Hello Robert,

    To define specific PHP version for all users, you may create file "/etc/profile.d/change_php.sh"
    With the following content:
    #!/bin/sh
    PATH="/opt/plesk/php/7.1/bin:$PATH"

    0
    Comment actions Permalink
  • Avatar
    Adrien

    Hello, thank you for the article, it helped me but I still can't solve a problem.

    When I am connected to the server via SSH and I run the following command, I have the expected result.

    $ php -v
    PHP 7.3.12 (cli) (built: Nov 22 2019 14:08:58) ( NTS )

    But when I run the following command from a local console (SSH Public Key Authentication), I have the PHP version which is installed with operating system :

    ssh my_server php -v
    PHP 5.4.16 (cli) (built: Nov 1 2019 16:04:20)

    Is it possible to use the version of PHP that I defined ?

    Thank you for your help.

    0
    Comment actions Permalink
  • Avatar
    Anton Maslov

    When you run command remotely without being logged to server itself, .bashrc is not executed. Use full path instead:

    ssh my_server /opt/plesk/php/7.3/bin/php -v
    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request