Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I currently have 2 version of php installed on ubuntu 12.04.

one for php 5.3 installed using apt-get while the other one is installed with xampp with php 5.5

When i execute these commands:

> which php
/usr/bin/php

> php --version
PHP 5.3.10-1ubuntu3.8 with Suhosin-Patch (cli) (built: Sep  4 2013 20:05:42) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethan

>echo $PATH
/home/chanhxc/bin
/usr/lib/lightdm/lightdm
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/opt/lampp/bin
/home/chanhxc/pear/bin
/home/chanhxc/.composer/vendor/bin
/opt/lampp/bin
/home/chanhxc/bin
/usr/lib/lightdm/lightdm
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/home/chanhxc/bin
/usr/lib/lightdm/lightdm
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/opt/lampp/bin
/home/chanhxc/pear/bin
/home/chanhxc/.composer/vendor/bin
/opt/lampp/bin

How do i make php 5.5 the default version to be run?

Btw, my default shell is zsh. here's the line in my .zshrc

export   PATH=$PATH:/home/chanhxc/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    # xampp, pear, composer
export PATH=$PATH:/opt/lampp/bin:/home/chanhxc/pear/bin:/home/chanhxc/.composer/vendor/bin:/opt/lampp/bin

Update

If i'm opting for the update-alternatives option. Here's what i currently have.

>update-alternatives --query php
Link: php
Status: auto
Best: /usr/bin/php5
Value: /usr/bin/php5

Alternative: /usr/bin/php5
Priority: 50
Slaves:
 php.1.gz /usr/share/man/man1/php5.1.gz
share|improve this question

1 Answer 1

There are a million things you can do instead of changing your $PATH.

One is to define an alias in your /home/YOUR_NAME/.bashrc file,

alias myphp=' /path/to/my/favorite/php ' 

Another one is to rename the version of php that you do not want, and to transform /usr/bin/php in a symbolic link to the version you wish to use:

sudo mv /usr/bin/php /usr/bin/php_5.3.10
sudo ln -s /path/to/php/you/want /usr/bin/php

Or you may use the Debian alternatives system. First, you install a php alternative,

 sudo update-alternatives --install "/usr/bin/php" "php" "/pathto/your/favorite/php" 1 

then you control that everything's fine by means of

sudo update-alternatives --display php

And much, much more.

share|improve this answer
    
thanks for the suggestion. but what's the best way there. i actually have an alias as phplatest with php 5.5 version. would soft linking php in /usr/bin/php makes the other version in xampp be default? –  chanHXC Nov 4 '13 at 13:03
    
btw, what exactly does an update-alternative command do? –  chanHXC Nov 4 '13 at 13:06
    
Keeps tab of which programs, all providing the same service, you prefer to use. Like having Chrome, Chromium, Firefox, Iceweasel on the same pc, which one should open when you click on alink in an e-mail? The one update-alternatives has indicated as the master. –  MariusMatutiae Nov 4 '13 at 13:26
    
ok thanks. but why do i get unknown argument `php'. when executing update-alternatives –  chanHXC Nov 4 '13 at 13:29
    
@chanHXC That's because I made an error in the syntax. I have updated my post, it should now work. Remember to move the existing php to /usr/bin/php_old –  MariusMatutiae Nov 4 '13 at 14:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.