Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...