Mac / OSx - change the version of PHP that is called in bash

I have a problem with PHP that invokes the bash php command:

In bash:

php -v # PHP 5.3.17

/ usr / bin / php # PHP 5.3.15

I want the secondary version of PHP 5.3.15 to be basically because in this version I installed extensions correctly, etc.

How can I set / usr / bin / php as the main → I want when the call to "php -v" returns my version 5.3.15.

Avoid my bad English, I hope you understand.

Thank you very much. I have a Mac OSx Lion

+7
source share
5 answers

I would recommend you install php through "Mac ports".

You have installed several versions of php.

With the cli "which" command, you can:

DESCRIPTION The utility accepts a list of command names and looks for the path for each executable file that will be run if these commands were actually called.

So read the man pages for the cli "which" command.

Make it from your cli:

which php

and then you will see where your php executable is located. I would recommend that you replace the php executable for a symlink to your / usr / bin / php.

+3
source

Another way, without changing the source file / php link, is to modify the .bashrc file as follows (also works with other commands):

  • Open Terminal / Command Prompt and type:

    vim ~/.bashrc 
  • Then press ā€œiā€ to switch to edit mode (if there was a problem before, due to the swap file, then press ā€œEā€ to edit the file anyway)
  • Add the following line (change the path as necessary):

     alias php="/Applications/MAMP/bin/php/php5.4.10/bin/php" 
  • Press "ESC" and enter ": wq"
  • If you need php-alias to work directly from your current shell session, you need to use the following command (this is optional, therefore, only if ur continues to work in your current shell):

     source ~/.bashrc 

So that it does not change in the / usr / bin folder, and you can export the bashrc file / settings to any other linux / bsd system, if necessary, without even touching the OS / usr / bin files. You can also add new aliases for different php versions, aliases like "php52", "php53", "php54", etc. For testing purposes or in general.

Good luck, ioCron

+6
source

For brew users, you may not need php55 if you already have 54 - but no matter what, you should probably run these commands

 $ brew install php54 php54-xdebug php54-mcrypt 

you can replace 54 with the last number if you want. last i checked that he was at 56

then, based on some comments above, you should run:

 $ php --version 

it will probably display:

 PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies 

if so, then change your .bash_profile as some of the other commentators my brew instance (I think its default value) lives in

 /usr/local/Cellar /usr/local/bin 

as soon as everything is installed using brew, they will be placed in the basement and connected through the basket. but in this case we need to override php

 $ sudo nano ~/.bash_profile 

my kinda looks like this:

 PATH=$PATH:~/bin PATH=$PATH:/usr/local/bin PATH=$PATH:/usr/local/sbin PATH=$PATH:/usr/local/Cellar/r/2.15.1/R.framework/Versions/Current/Resources/li$ export PATH 

which means that it already has access to / usr / local / bin - but I use an alias to indicate adding this line at the bottom:

 alias php="/usr/local/bin/php" 

save and close the terminal window, open another one, and it should show something like:

 $ php --version PHP 5.4.27 (cli) (built: Apr 24 2014 17:16:35) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies with Xdebug v2.2.4, Copyright (c) 2002-2014, by Derick Rethans 
+5
source

OS: OSX Yosemite
Just select a similar problem on vim ~/.bash_profile

export PATH = / usr / local / bin: $ PATH
export PATH = / Applications / MAMP / bin / php / php5.5.10 / bin: $ PATH

Make sure the order is correct. Put export PATH=/usr/local/bin:$PATH to export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH

/ usr / local / bin contains the default macro.

Hope this helps.

+4
source

You must find the path and check all directories in the path for a symbolic link to the wrong php version.

You can then remove this symbolic link and replace it with a link to the correct version.

You can also use find to see all instances:

 $ sudo find / -name "php" 
+1
source

All Articles