在 mac 上更新 php 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41872645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Updating php version on mac
提问by Morpheus
I want to update php version, currently I have 5.5.38 and I want 7.1
我想更新 php 版本,目前我有 5.5.38,我想要 7.1
What I tried so far is using this command:
到目前为止我尝试过的是使用这个命令:
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1
I tried several different versions but none of them worked.
It opens bash_profile for a second and then I get Received SIGHUP or SIGTERM
and message below:
我尝试了几个不同的版本,但没有一个有效。它打开 bash_profile 一秒钟,然后我收到Received SIGHUP or SIGTERM
以下消息:
Buffer written to /Users/Morpheus/.bash_profile.save.6
缓冲区写入 /Users/Morpheus/.bash_profile.save.6
Not sure what went wrong and why it won't update...
不知道出了什么问题,为什么它不会更新......
Any ideas?
有任何想法吗?
Thanks.
谢谢。
采纳答案by Viktor
回答by Prashant Barve
The simplest way to update the version of php on Mac is via Homebrew.
在 Mac 上更新 php 版本的最简单方法是通过 Homebrew。
If you do not have brew please visit https://brew.sh/or install via command in terminal:
如果您没有 brew,请访问https://brew.sh/或通过终端中的命令安装:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
When finished installing Homebrew, run the following commands:
安装 Homebrew 后,运行以下命令:
brew update && brew upgrade
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew unlink php@56
brew install php@71
You might get an error if PHP 5.6 has not been installed by brew previously, but don't worry, you can simply continue.
如果之前 brew 没有安装 PHP 5.6,你可能会得到一个错误,但别担心,你可以继续。
You can also change the version to 7.0 by replacing the command from above commands from brew install php@71
to brew install php@70
.
您还可以通过将上述命令中的命令从brew install php@71
to替换为 7.0 版本brew install php@70
。
You can check the output by command.
您可以通过命令检查输出。
php -v
If the output of php -v
still doesn't echoes the version 7, simply type this command and hit enter in terminal.
如果输出php -v
仍然没有与版本 7 相呼应,只需键入此命令并在终端中按回车键即可。
export PATH=/usr/local/php5/bin:$PATH
回答by matinict
Install php
安装 php
brew install [email protected]
Install the required PHP to your PATH
将所需的 PHP 安装到您的 PATH
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
Then make sure it's all working
然后确保一切正常
php -v
php --version
This command will show you where your ini file is loaded
此命令将显示您的 ini 文件的加载位置
php --ini
回答by ??ng Qu?c Anh
Try to use below command
尝试使用以下命令
brew update
brew install php@72
brew update
brew install php@72
If it shows below error,
如果显示以下错误,
"Error: No available formula with the name "php"
“错误:没有名称为“php”的可用公式
try
尝试
brew install [email protected]
brew install [email protected]
回答by gzchen
You can brew upgrade php7
or brew uninstall
old php version.
你可以brew upgrade php7
或brew uninstall
旧的php版本。
Last, I recommend you brew install php-version
, php-version can help you change your php version
最后,我推荐你brew install php-version
,php-version 可以帮你修改你的php版本
回答by Sajjad Aljileezi
try to use the command, its working fine with me
尝试使用该命令,它对我来说很好用
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
回答by Duy Nguyen
In case you guys run all install commands above but when checking the PHP version, it is still linking to the old version. So you guys may want to update the PATH
.
如果你们运行上面的所有安装命令,但是在检查 PHP 版本时,它仍然链接到旧版本。所以你们可能想要更新PATH
.
In my case, I open the .bash_profile
which located in HOME
directory by command:
就我而言,我通过命令打开.bash_profile
位于HOME
目录中的文件:
nano ~/.bash_profile
Then, I add the path to the new version of PHP:
然后,我将路径添加到新版本的 PHP:
PATH=/usr/local/Cellar/php/7.4.4/bin:<other_paths>
Finally, run source ~/.bash_profile
command to refresh the terminal window and checking the PHP version again.
最后,运行source ~/.bash_profile
命令以刷新终端窗口并再次检查 PHP 版本。
Hope this helps.
希望这可以帮助。