6

I'm trying to figure out how to change which version of PHP the php alias uses...

I want it to use: /opt/plesk/php/5.6/bin/php

But it currently uses: /usr/bin/php (I think)

How can I ensure that when typing php through SSH, that it's using the updated plesk version?

0

2 Answers 2

4

Create an alias. First determine the default shell that is running when you login via ssh.

echo $SHELL
/bin/bash

Assume it's bash.

In your user home directory, have the file: .bashrc

add:

alias pphp="/opt/plesk/php/5.6/bin/php"

save. Log out. Log back in. Or just reload .bashrc via source:

source .bashrc

Then to launch plesk php, just type pphp as the command rather than php alone.

Test to make sure this meets your needs.

If your default shell is not bash, just look up how to create an alias for that shell.

6
  • This is great, but I need the alias to be php because some composer scripts that are run automatically during updates to Laravel assume the command... is that a problem?
    – dcolumbus
    Nov 10, 2015 at 5:47
  • That's different. php is not an alias, it's the actual file name of the executable. Located by: which php, usually something like: /usr/bin/php. which gives the system path, assuming the path of the program is in $PATH, it just looks through the $PATH data until it finds the application name, php in this case. I can't comment on things like plesk plus something else because it's not something I would ever use, too complicated, too much room for error. If some scripts run automatically, it's harder to set different paths since they are running as a different user than you, like www-data etc.
    – Lizardx
    Nov 10, 2015 at 6:05
  • Plesk isn't running separate scripts... I'm installing Laravel, which automatically executes an "artisan" command that utilizes php.
    – dcolumbus
    Nov 10, 2015 at 16:56
  • Is there no way to switch out the version of php that is located at /usr/bin ?
    – dcolumbus
    Nov 10, 2015 at 17:09
  • If you have root on the system, you can install whatever you like. If you don't, you can't. Current php is 5.6, well, actually 7 now, but you'd be installing 5.6. I avoid commenting on things like plesk/cpanel because they are such horrible internal messes that it grows very hard to predict what a system that has them installed will do when you try to run the server as if they were not there. I realized we hadn't even checked your local real system php version: php --version
    – Lizardx
    Nov 10, 2015 at 20:11
1

This question has been asked by me under this exact context in the past and answered here:

PHP CLI and Bash - change behaviour of PHP keyword

You can attack this in a variety of ways.

Method #1 - alias

You can make an alias, php=php-5.4, and then attempt to run your script. Assuming that it relies on the current shells ability to locate how to run things, then it should pickup the alias for php instead of the php that's located under /usr/bin.

Method #2 - $PATH

You can override the precendence of where shells locate executables by manipulating the $PATH environment variable. Simply add the location of some other directory to the front of the $PATH.

export PATH=/path/to/newdir:$PATH

Now put a shell script or link in this directory named php. Here's the script:

#!/bin/bash

php-5.4 $*

Here's the link:

$ cd /path/to/newdir
$ ln -s /usr/bin/php-5.4 php

Not the answer you're looking for? Browse other questions tagged .