简体   繁体   English

Mac将PHP升级到5.6,但是CLI php -v得到5.3.28?

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

I have installed MAMP (comes with PHP 5.5) on my machine. 我已经在计算机上安装了MAMP(PHP 5.5附带)。 And localhost pointed to /Applications/MAMP/htdocs. 本地主机指向/ Applications / MAMP / htdocs。 The problem happened when I was trying to use composer in terminal to install dependencies in htdocs. 当我尝试在终端中使用composer在htdocs中安装依赖项时,发生了问题。 Composer complained that PHP must be 5.4 or above. 作曲家抱怨PHP必须为5.4或更高版本。

I guess it complained about PHP comes with OSX. 我猜它抱怨OSX附带了PHP。 So I have upgraded PHP to 5.6 by 所以我通过以下方式将PHP升级到5.6

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... 而且Composer仍在抱怨...

Why is that? 这是为什么? And how to fix this? 以及如何解决这个问题?

If you have upgraded using curl, copy & paste the following line of code and press enter. 如果已使用curl升级,请复制并粘贴以下代码行,然后按Enter。

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

Now, type $ php -v 现在,键入$ 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 PHP 5.6.23(cli)(内置:2016年6月26日13:17:47)版权所有(c)1997-2016 The PHP Group Zend Engine v2.6.0,版权所有(c)1998-2016 Zend Technologies with Zend OPcache v7.0.6 -dev,Zend Technologies使用Xdebug v2.2.5版权所有(c)1999-2016,Derick Rethans版权所有(c)2002-2014

If you installed PHP 5.6 using Homebrew , this works: 如果您使用Homebrew安装了PHP 5.6,则可以:

Open Terminal, run open -a TextEdit ~/.bash_profile , then paste this in the end of the file: 打开终端,运行open -a TextEdit ~/.bash_profile ,然后将其粘贴到文件末尾:

# 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. 保存文件并重新启动终端。

Thanks for the help. 谢谢您的帮助。

It is due to the order in $PATH, like Marc and jkj posted in the comments above. 这是由于$ PATH中的顺序所致,就像上面评论中发布的Marc和jkj一样。

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: 我找不到重新排序$ PATH的方法(进行了一些研究,但没有找到简单的方法),但是我可以通过简单地删除此帖子后先前安装的Apahce2来解决此问题:

https://apple.stackexchange.com/questions/41143/how-to-revert-default-mac-apache-install-to-original 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. 2014年9月9日更新:经过研究后,以下过程将使PHP版本设置系统广泛。

The procedure comes from this source , please look for the comments down below that page and find user Amtriorix. 该过程来自此来源 ,请在该页面下方查找注释,并找到用户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... 
  1. Look at the terminal history to see where the new version was installed (probably /usr/local) 查看终端历史记录以查看新版本的安装位置(可能是/ usr / local)
  2. Type 'which php' into terminal to see where current version is located (this should be different that new version) 在终端中输入“哪个php”,以查看当前版本的位置(此版本应与新版本不同)
  3. Go to users/username/.bash_profile 转到用户/用户名/.bash_profile
  4. Replace the old location with the new location, or add another location after the original location, separated by a colon (if you replace, you may break something else, depending on location). 用新位置替换旧位置,或在原始位置之后添加另一个位置,并用冒号分隔(如果替换,则可能会破坏其他位置,具体取决于位置)。
  5. Restart terminal, run php -v to test. 重新启动终端,运行php -v进行测试。

     export PATH="/usr/local/mysql/bin:/usr/local/bin:/usr/local:$PATH" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM