Mac upgraded PHP to 5.6, but CLI php -v get 5.3.28?

15,220

Solution 1

If you have upgraded using curl, copy & paste the following line of code and press enter.

$ export PATH=/usr/local/php5/bin:$PATH

Now, type

$ php -v

If done correctly, it should show the following

PHP 5.6.23 (cli) (built: Jun 26 2016 13:17:47) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

Solution 2

If you installed PHP 5.6 using Homebrew, this works:

Open Terminal, run open -a TextEdit ~/.bash_profile, then paste this in the end of the file:

# Use Home-brewed PHP 5.6 instead of pre-installed version (5.3)
export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"

Save the file and restart Terminal.

Solution 3

Thanks for the help.

It is due to the order in $PATH, like Marc and jkj posted in the comments above.

I can't find a way to re-order the $PATH (did some research but failed to find an easy way), but I am able to fix this by simply removing the Apahce2 previously installed following this post:

https://apple.stackexchange.com/questions/41143/how-to-revert-default-mac-apache-install-to-original

update 9/9/2014: after some research, the following procedure would make PHP version setting system wide.

The procedure comes from this source, please look for the comments down below that page and find user Amtriorix.

I am just copy/paste his solution here:

  The php-cli version is still the Apple version if You do not change it. Your php on apache can be different as the cli version, including used modules ! So beware.
    As Brian Wynn did mention, of course You can modify Your PATH settings to write into your ~/.profile file the following
    export PATH=/usr/local/php5/bin:$PATH
    Most likely a better approach is to make the setting system wide.
    You should symlink to the right php executable.
    So:
    #cd /usr/bin
    #mv php php.org
    #ln -s /usr/local/php5/bin/php
    test if it works:
    #php -v && php -m && php --ini
    --> should be php-osx version with related modules...
Share:
15,220
bing
Author by

bing

Updated on June 08, 2022

Comments

  • bing
    bing almost 2 years

    I have installed MAMP (comes with PHP 5.5) on my machine. And localhost pointed to /Applications/MAMP/htdocs. The problem happened when I was trying to use composer in terminal to install dependencies in htdocs. Composer complained that PHP must be 5.4 or above.

    I guess it complained about PHP comes with OSX. So I have upgraded PHP to 5.6 by

    curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
    

    But when I do

    $ php -v
    

    I still get

    PHP 5.3.28 (cli) (built: Aug 29 2014 18:52:17) 
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
    

    And Composer is still complaining...

    Why is that? And how to fix this?