Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac / OSx - Change PHP version which is call in bash

Tags:

I have a problem with PHP which is call through bash command "php":

In bash:

php -v # PHP 5.3.17

/usr/bin/php # PHP 5.3.15

I want secondary PHP version 5.3.15 as mainly, because in this version I have correctly installed extensions etc.

How can I set /usr/bin/php as main -> I want when call "php -v" return my 5.3.15 version.

Execuse my bad English, I hope that you understand.

Thank you so much. I have Mac OSx Lion

like image 228
frosty22 Avatar asked Nov 08 '12 21:11

frosty22


People also ask

What version of PHP do I have Mac terminal?

The php -v command works on Linux, macOS, Windows, and other supported systems. Its output contains the PHP version number, build date, and copyright information. Note: If there is more than one PHP version installed on the server, the php -v command shows the default command-line interface (CLI) version.


1 Answers

Another way without changing the original php file / link is if you edit your .bashrc file as follows (works with other commands as well):

  1. Open your Terminal / Commandline and type in:

    vim ~/.bashrc 
  2. Then press "i" to get into edit-mode (if there shows up a problem before that, because of a swap file, then press "E" to edit the file anyway)
  3. Add the following line (change the path as needed):

    alias php="/Applications/MAMP/bin/php/php5.4.10/bin/php" 
  4. Press "ESC" and type in ":wq"
  5. If you need the php-alias to work right out of your current shell-session, then you have to use the following command (that's optional, so only if u r continuing to work in your current shell):

    source ~/.bashrc 

That's it, no change in the /usr/bin folder needed, and u can export your bashrc file / settings to any other linux / bsd like system if needed without even touching your OS /usr/bin files. You can also add new aliases for different php versions, aliases like "php52", "php53", "php54", etc. for testing purposes or whatsoever.

Have fun, ioCron

like image 106
ioCron Avatar answered Oct 13 '22 13:10

ioCron