3

Our hosting providers have installed 3 versions of PHP onto our linux box and when I SSH into it the command php points to use/bin/php which is version 5.2, the command php-5.4 points to usr/bin/php-5.4 which is version 5.4 of course.

This isn't a problem when I just need to run a single script that needs a newer version of php, I can just specify php-5.4, however when I try to run the Laravel installer or try to install Laravel using Composer it is throwing errors that are caused by php 5.2 being used.

Is there a way to change where the php keyword points? Or do I need to remove bin/php and rename bin/php-5.4?

3

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
  • Method 2 Worked perfectly, composer was able to install Laravel first try, php -v confirms version 5.4 is being executed. – bgld Oct 23 '14 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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