如何在 Mac OS X 中升级 PHP?
我觉得这是一个非常愚蠢的问题,但奇怪的是,这个问题的记录很少。
我想升级 PHP,但有几个问题:
- 没有内置的包管理器。 MacPorts 无法将 php 识别为已安装的软件包,因为它本身没有安装 PHP。
- 运行
locate php
表明可能存在许多依赖项。 - 我不知道 php 是如何安装的,因为它包含在操作系统中,所以我不知道是否应该从源代码安装或下载二进制文件。我也不知道在不破坏依赖关系的情况下卸载以前版本的正确方法。
我在豹子上奔跑。我有一种感觉 Apple 不希望你升级。购买 Snow Leopard 并升级可以解决这个问题(以及未来的类似问题)吗?
I feel this is an awfully obtuse question to ask, but strangely, this problem is poorly documented.
I would like to upgrade PHP, but there are several problems:
- There is no built-in package manager. MacPorts doesn't recognize php as an installed package because it didn't install PHP itself.
- Running
locate php
indicates there are probably many dependencies. - I don't know HOW php was installed, as it was included with the OS, so I don't know whether I should install from source or download binaries. I also don't know the proper way to uninstall the previous version without breaking dependencies.
I am running on Leopard. I have a feeling Apple doesn't want you to upgrade. Would buying Snow Leopard and upgrade solve this problem (and future ones like it)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
您可能想查看 Marc Liyanage 的 PHP 包。它包含在一个漂亮的 Mac OS X 安装程序包中,您可以双击该安装程序包。他保持最新状态。
http://php-osx.liip.ch/
另外,虽然升级到 Snow Leopard 不会帮助您将来进行 PHP 更新,它可能会为您提供更新版本的 PHP。我运行的是 OS X 10.6.2,它有 PHP 5.3.0。
You may want to check out Marc Liyanage's PHP package. It comes in a nice Mac OS X installer package that you can double-click. He keeps it pretty up to date.
http://php-osx.liip.ch/
Also, although upgrading to Snow Leopard won't help you do PHP updates in the future, it will probably give you a newer version of PHP. I'm running OS X 10.6.2 and it has PHP 5.3.0.
我使用这个: https://github.com/Homebrew/homebrew-php
命令是:
然后在您的 <代码>.bash_profile或
.bashrc
I use this: https://github.com/Homebrew/homebrew-php
The command is:
Then config in your
.bash_profile
or.bashrc
我认为一种简单的方法是:
1 - 检查当前的 PHP 在哪里:
看到了吗?通常,我们运行的命令是 /usr/local/bin 中的链接,因此...
2 - 取消链接 PHP 的当前链接
如果您愿意,在取消链接之前,检查路径,然后删除 php 文件(执行
ls -al /usr/local/bin
| grep php 然后rm -rf
进入所需路径)3 - 安装 PHP 7.1
4 - 创建新链接(使用您拥有的 php 7.1 bin)安装)
就像我说的,我认为这是一种简单的方法。
I think one simple way to do it, is:
1 - Check you where is your current PHP:
You see? Usually, our commands that we run is a link in /usr/local/bin so...
2 - Unlink this current link of PHP
If you prefere, before unlink it, check the path and then remove php files (do
ls -al /usr/local/bin
| grep php and thenrm -rf
into desired path)3 - Install PHP 7.1
4 - Create new link (using php 7.1 bin that you have installed)
Like I said, its a simple way I think.
您仍然可以使用 MacPorts 安装它。
sudo port install php52
(或您想要的任何版本)将安装 PHP。它不会覆盖 Apple 提供的版本。它将安装在
/opt/local
下。您可以将/opt/local
添加到$PATH
的开头,并在 Apache 配置中使用 MacPorts 版本。You could still install it with MacPorts.
sudo port install php52
(or whichever version you want) will install PHP.It won't overwrite the Apple-supplied version. It'll install it under
/opt/local
. You can add/opt/local
to the beginning of your$PATH
, and use the MacPorts version in your Apache config.选项#1
按照此处的建议,此站点提供了方便、最新的一则说明。
这不会覆盖系统上 PHP 的基本版本,而是将其干净地安装在 /usr/local/php5 中。
选项 #2
我的首选方法是通过 Homebrew 安装。
Option #1
As recommended here, this site provides a convenient, up-to-date one liner.
This doesn't overwrite the base version of PHP on your system, but instead installs it cleanly in /usr/local/php5.
Option #2
My preferred method is to just install via Homebrew.
在继续之前,我有最新版本 (v5.0.15) 的 OS X Server (是的,可怕,我知道......但是,网络服务器似乎工作正常)。我连续几天四处搜寻,试图更新(或者至少让 Apache 指出)新版本的 PHP。我的
mcrypt
和其他扩展都不起作用,我从 安装并重新安装了 PHP 无数次http://php-osx.liip.ch/ 和其他教程,直到我终于注意到在许多不同的之一的评论中写了一些信息。 OS X Server 保存的conf
文件是 OS X Server 在加载 Apachehttpd.conf
之前加载它自己的自定义.conf
文件(位于在/etc/apache2/httpd.conf
)。服务器文件位于:当您打开此文件时,您必须像这样注释掉这一行:
然后添加正确的路径 (如果您是通过 http://php-osx.liip.ch/链接):
经过此修改,我的PHP终于加载了正确的PHP 安装。话虽这么说,如果事情变得不稳定,可能是因为 OS X 是在安装 OS X 时就脱离了 PHP 的本机安装的。要恢复,只需撤消上面的更改即可。
无论如何,希望这对其他花费无数时间于此的人有所帮助。
Before I go on, I have the latest version (v5.0.15) of OS X Server (yes, horrible, I know...however, the web server seems to work A-OK). I searched high and low for days trying to update (or at least get Apache to point to) a new version of PHP. My
mcrypt
did not work, along with other extensions and I installed and reinstalled PHP countless times from http://php-osx.liip.ch/ and other tutorials until I finally noticed a tid-bit of information written in a comment in one of the many different.conf
files OS X Server keeps which was that OS X Server loads it's own custom.conf
file before it loads the Apachehttpd.conf
(located at/etc/apache2/httpd.conf
). The server file is located:When you open this file, you have to comment out this line like so:
Then add in the correct path (which should already be installed if you have installed via the http://php-osx.liip.ch/ link):
After this modification, my PHP finally loaded the correct PHP installation. That being said, if things go wonky, it may be because OS X is made to work off the native installation of PHP at the time of OS X installation. To revert, just undo the change above.
Anyway, hopefully this is helpful for anyone else spending countless hours on this.
升级到 Snow Leopard 并不能解决保持 PHP 最新的主要问题。苹果并不总是将其捆绑的第三方软件与操作系统更新保持同步。依赖苹果为你提供所需的错误修复/安全更新是自找麻烦。
此外,我建议通过 MacPorts 安装(并进行必要的配置来使用它,而不是 Apple 的 PHP),而不是尝试就地升级 Apple 提供的 PHP。您对
/usr/bin
所做的任何操作都有可能被未来的 Apple 更新覆盖。Upgrading to Snow Leopard won't solve the your primary problem of keeping PHP up to date. Apple doesn't always keep the third party software that it bundles up to date with OS updates. And relying on Apple to get you the bug fix / security update you need is asking for trouble.
Additionally, I would recommend installing through MacPorts (and doing the config necessary to use it instead of Apple's PHP) rather than try to upgrade the Apple supplied PHP in place. Anything you do to
/usr/bin
risks being overwritten by some future Apple update.节省击键次数,这在 MacOS Sierra 上有效:
Saving on keystrokes, this worked on MacOS Sierra:
使用以下命令在终端中检查当前的 php 版本,
您会在终端中看到当前的 php 版本,如果您想使用 php concat 升级 php 版本,请在终端中运行下一个命令,
如果您完成了 php 版本,请重新启动终端升级安装并运行命令。
现在你在终端中看到当前的 php 版本....谢谢
Check your current php version in terminal with the following command,
You see current php version in terminal, and next command run in terminal if you want to upgrade your php version with php concat with version liked as,
Please restart terminal if you finished php version upgrade installed and run the command.
Now you see the current php version in terminal....thank
使用这个命令:
Use this Command:
您可以使用curl来更新php版本。
最后一步:
检查升级版本
You can use curl to update php version.
Last Step:
Check the upgraded version
最好的升级方法是
从源代码编译它
请参阅本教程,这可能对您有帮助
http://www.computersnyou.com/2012/09/how-to-upgrade-php-in-mac-osx-compiling.html
best way to upgrade is
compile it from source
see this tutorial that may be helful for you
http://www.computersnyou.com/2012/09/how-to-upgrade-php-in-mac-osx-compiling.html
将php7升级到最新稳定版本
brew升级php7
或者对于 php5.X 到最新稳定版本,
请使用
brew list
检查已安装的版本to upgrade php7 to latest stable version
brew upgrade php7
or for php5.X to latest stable version
use
brew list
to check installed version