skip to Main Content

I’m working on a Ubuntu 16 machine:

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.6 LTS
Release:        16.04
Codename:       xenial

My experience with Ubuntu is “medium”.

I needed to change the path the php command refers to in alternatives.
I did the following:

cd /etc/alternatives
ls -ls | grep php
0 lrwxrwxrwx 1 root root  15 Mar  7 06:31 php -> /usr/bin/php7.0

I want to change the path /usr/bin/php7.0 to /opt/plesk/php/7.2/bin/php.

The first thing I tried is update-alternatives --config php.
This gave me this:

There is 1 choice for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
  0            /usr/bin/php7.0   70        auto mode
* 1            /usr/bin/php7.0   70        manual mode

Press <enter> to keep the current choice[*], or type selection number:

Sadly, I can’t add another path by using this command.

The second thing I tried to do is this: update-alternatives --set php /opt/plesk/php/7.2/bin/php. The result of that:

update-alternatives: error: alternative /opt/plesk/php/7.2/bin/php for php not registered; not setting

The third attempt, I went to /etc/alternatives and used unlink php. Then I created a new symlink like this: ln -s /opt/plesk/php/7.2/bin/php php.
This changed the path in alternatives indead. See for yourself:

root@xxtweb03:/etc/alternatives# ls -ls | grep php
0 lrwxrwxrwx 1 root root  26 Apr  4 12:18 php -> /opt/plesk/php/7.2/bin/php

It has only one disadvantage.
When I run this command: update-alternatives --config php then the /opt/plesk/php/7.2/bin/php is not among the selection.

This is what I get:

root@xxtweb03:/# update-alternatives --config php
There is 1 choice for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
  0            /usr/bin/php7.0   70        auto mode
  1            /usr/bin/php7.0   70        manual mode

Question: how can I add /opt/plesk/php/7.2/bin/php to the Path list that is displayed when running update-alternatives --config php?

2

Answers


  1. you have to install alternative path first to display it in alternatives list,
    see manual page
    by using this command,

    update-alternatives --install /usr/bin/php php /opt/plesk/php/7.2/bin/php 71

    it will install your /opt/plesk/php/7.2/bin/php into alternatives list

    Login or Signup to reply.
  2. I had to append an additional and mandatory option priority. The value has to be an integer.

    This worked for me:

    sudo update-alternatives --install /usr/bin/php php /opt/plesk/php/7.2/bin/php 100
    

    Maybe you also want to add alternatives of these commands:

    • phar
    • phar.phar
    • php-cgi
    • php-cgi-bin

    These commands will add alternatives for all five commands (also called link groups):

    sudo update-alternatives --install /usr/bin/php php /opt/plesk/php/7.2/bin/php 100
    sudo update-alternatives --install /usr/bin/phar phar /opt/plesk/php/7.2/bin/phar 100
    sudo update-alternatives --install /usr/bin/phar.phar phar.phar /opt/plesk/php/7.2/bin/phar.phar 100
    sudo update-alternatives --install /usr/bin/php-cgi php-cgi /opt/plesk/php/7.2/bin/php-cgi 100
    sudo update-alternatives --install /usr/lib/cgi-bin/php php-cgi-bin /opt/plesk/php/7.2/bin/php-cgi 100
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search