如何在 Mac OS X 中升级 PHP?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2526085/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:49:56  来源:igfitidea点击:

How do I upgrade PHP in Mac OS X?

phpmacosmacports

提问by thebossman

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:

我想升级PHP,但是有几个问题:

  • 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 phpindicates 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.
  • 没有内置的包管理器。MacPorts 不会将 php 识别为已安装的软件包,因为它没有安装 PHP 本身。
  • 运行locate php表明可能有很多依赖项。
  • 我不知道 php 是如何安装的,因为它包含在操作系统中,所以我不知道应该从源代码安装还是下载二进制文件。我也不知道在不破坏依赖关系的情况下卸载以前版本的正确方法。

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)?

我在 Leopard 上运行。我有一种感觉,Apple 不想让您升级。购买 Snow Leopard 并升级会解决这个问题(以及未来的类似问题)吗?

采纳答案by Scott Saunders

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.

您可能想查看 Marc Liyanage 的 PHP 包。它带有一个很好的 Mac OS X 安装程序包,您可以双击它。他保持最新状态。

http://php-osx.liip.ch/

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.

此外,虽然升级到 Snow Leopard 不会帮助您在未来进行 PHP 更新,但它可能会为您提供更新版本的 PHP。我运行的是 OS X 10.6.2,它有 PHP 5.3.0。

回答by Taro Alan

I use this: https://github.com/Homebrew/homebrew-php

我用这个:https: //github.com/Homebrew/homebrew-php

The command is:

命令是:

$ xcode-select --install

$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/homebrew-php

$ brew options php56
$ brew install php56

Then config in your .bash_profileor .bashrc

然后在您的.bash_profile.bashrc

# Homebrew PHP CLI
export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"

回答by Paulo Victor

I think one simple way to do it, is:

我认为一种简单的方法是:

1 - Check you where is your current PHP:

1 - 检查您当前的 PHP 在哪里:

$ which php
$ /usr/local/bin/php

You see? Usually, our commands that we run is a link in /usr/local/bin so...

你看?通常,我们运行的命令是 /usr/local/bin 中的链接,所以...

2 - Unlink this current link of PHP

2 - 取消链接当前的 PHP 链接

unlink /usr/local/bin/php

If you prefere, before unlink it, check the path and then remove php files (do ls -al /usr/local/bin| grep php and then rm -rfinto desired path)

如果你喜欢,在取消链接之前,检查路径,然后删除 php 文件(做ls -al /usr/local/bin| grep php 然后rm -rf进入所需的路径)

3 - Install PHP 7.1

3 - 安装 PHP 7.1

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

4 - Create new link (using php 7.1 bin that you have installed)

4 - 创建新链接(使用您已安装的 php 7.1 bin)

ln /usr/local/php5-7.1.9-20170914-100859/bin/php /usr/local/bin/php

Like I said, its a simple way I think.

就像我说的,这是我认为的一种简单方法。

回答by mipadi

There is no built-in package manager. MacPorts doesn't recognize php as an installed package because it didn't install PHP itself.

没有内置的包管理器。MacPorts 不会将 php 识别为已安装的软件包,因为它没有安装 PHP 本身。

You could still install it with MacPorts. sudo port install php52(or whichever version you want) will install PHP.

您仍然可以使用 MacPorts 安装它。sudo port install php52(或您想要的任何版本)将安装 PHP。

It won't overwrite the Apple-supplied version. It'll install it under /opt/local. You can add /opt/localto the beginning of your $PATH, and use the MacPorts version in your Apache config.

它不会覆盖 Apple 提供的版本。它将安装在/opt/local. 您可以添加/opt/local到您的$PATH, 并在您的 Apache 配置中使用 MacPorts 版本。

回答by user456584

Option #1

选项1

As recommended here, this siteprovides 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.

这不会覆盖系统上 PHP 的基本版本,而是将其干净地安装在 /usr/local/php5 中。

Option #2

选项#2

My preferred method is to just install via Homebrew.

我的首选方法是通过 Homebrew 安装

回答by Rasclatt

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 mcryptdid not work, along with other extensions and I installed and reinstalled PHP countless times from http://php-osx.liip.ch/and other tutorialsuntil I finally noticed a tid-bit of information written in a comment in one of the many different .conffiles OS X Server keeps which was that OS X Server loads it's own custom .conffile before it loads the Apache httpd.conf(located at /etc/apache2/httpd.conf). The server file is located:

在我继续之前,我有OS X Server的最新版本 (v5.0.15) (是的,太可怕了,我知道……但是,Web 服务器似乎工作正常)。我搜索了好几天试图更新(或至少让 Apache 指向)新版本的 PHP。我的mcrypt没有工作,以及其他扩展,我从http://php-osx.liip.ch/和其他教程无数次安装和重新安装 PHP 直到我终于注意到在其中一个评论中写的一点信息.confOS X Server 保留的许多不同文件,即 OS X Server.conf在加载 Apache httpd.conf(位于/etc/apache2/httpd.conf之前加载它自己的自定义文件。服务器文件位于:

/Library/Server/Web/Config/apache2/httpd_server_app.conf

When you open this file, you have to comment out this line like so:

当你打开这个文件时,你必须像这样注释掉这一行:

#LoadModule php5_module libexec/apache2/libphp5.so

Then add in the correct path (which should already be installed if you have installed via the http://php-osx.liip.ch/link):

然后添加正确的路径(如果您通过http://php-osx.liip.ch/链接安装,则应该已经安装了)

LoadModule php5_module /usr/local/php5/libphp5.so

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.

经过这次修改,我的PHP终于加载了正确的PHP安装。话虽如此,如果事情变得不稳定,可能是因为 OS X 在安装 OS X 时就可以脱离 PHP 的本机安装。要恢复,只需撤消上面的更改。

Anyway, hopefully this is helpful for anyone else spending countless hours on this.

无论如何,希望这对其他人花费无数小时有帮助。

回答by Dave Bacher

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.

升级到 Snow Leopard 并不能解决保持 PHP 最新的主要问题。Apple 并不总是将其捆绑的第三方软件与操作系统更新保持同步。依靠 Apple 为您提供所需的错误修复/安全更新是自找麻烦。

Additionally, I would recommend installing through MacPorts (and doing the config necessary to use it insteadof Apple's PHP) rather than try to upgrade the Apple supplied PHP in place. Anything you do to /usr/binrisks being overwritten by some future Apple update.

此外,我建议通过 MacPorts 进行安装(并进行必要的配置以使用它而不是Apple 的 PHP),而不是尝试升级 Apple 提供的 PHP。您所做的任何事情都有/usr/bin可能被未来的 Apple 更新覆盖。

回答by Cees Timmerman

Saving on keystrokes, this worked on MacOS Sierra:

节省击键,这适用于 MacOS Sierra:

$ brew install homebrew/php/php71

$ /usr/local/opt/php71/bin/php -v
PHP 7.1.4 (cli) (built: Apr 14 2017 15:02:16) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

回答by yekyawaung

Check your current php version in terminal with the following command,

使用以下命令在终端中检查您当前的 php 版本,

$ php -v

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,

您会在终端中看到当前的 php 版本,如果您想使用 php concat 升级您的 php 版本,则在终端中运行下一个命令,版本如下,

$ brew install homebrew/php/php71

Please restart terminal if you finished php version upgrade installed and run the command.

如果您完成安装 php 版本升级并运行命令,请重新启动终端。

$ php -v

Now you see the current php version in terminal....thank

现在您可以在终端中看到当前的 php 版本....谢谢

回答by Aghaie

Use this Command:

使用这个命令:

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