如何在 Mac OS X 中升级 PHP?

发布于 2024-08-26 12:33:58 字数 356 浏览 5 评论 0原文

我觉得这是一个非常愚蠢的问题,但奇怪的是,这个问题的记录很少。

我想升级 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

手心的海 2024-09-02 12:33:58

您可能想查看 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.

仲春光 2024-09-02 12:33:58

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

命令是:

$ xcode-select --install

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

$ brew options php56
$ brew install php56

然后在您的 <代码>.bash_profile或.bashrc

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

I use this: 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_profile or .bashrc

# Homebrew PHP CLI
export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"
同展鸳鸯锦 2024-09-02 12:33:58

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

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

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

看到了吗?通常,我们运行的命令是 /usr/local/bin 中的链接,因此...

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

unlink /usr/local/bin/php

如果您愿意,在取消链接之前,检查路径,然后删除 php 文件(执行 ls -al /usr/local/bin | grep php 然后 rm -rf 进入所需路径)

3 - 安装 PHP 7.1

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

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

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

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

I think one simple way to do it, is:

1 - Check you where is your current PHP:

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

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

2 - Unlink this current link of 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 -rf into desired path)

3 - Install 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)

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

Like I said, its a simple way I think.

〃安静 2024-09-02 12:33:58

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

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

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

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

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.

℡寂寞咖啡 2024-09-02 12:33:58

选项#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.

幸福%小乖 2024-09-02 12:33:58

在继续之前,我有最新版本 (v5.0.15) 的 OS X Server (是的,可怕,我知道......但是,网络服务器似乎工作正常)。我连续几天四处搜寻,试图更新(或者至少让 Apache 指出)新版本的 PHP。我的 mcrypt 和其他扩展都不起作用,我从 安装并重新安装了 PHP 无数次http://php-osx.liip.ch/ 和其他教程,直到我终于注意到在许多不同的 之一的评论中写了一些信息。 OS X Server 保存的conf 文件是 OS X Server 在加载 Apache httpd.conf 之前加载它自己的自定义 .conf 文件(位于在/etc/apache2/httpd.conf)。服务器文件位于:

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

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

#LoadModule php5_module libexec/apache2/libphp5.so

然后添加正确的路径 (如果您是通过 http://php-osx.liip.ch/链接)

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

经过此修改,我的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 Apache httpd.conf (located at /etc/apache2/httpd.conf). The server file is located:

/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):

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.

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

傲世九天 2024-09-02 12:33:58

升级到 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.

调妓 2024-09-02 12:33:58

节省击键次数,这在 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

Saving on keystrokes, this worked on 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
玻璃人 2024-09-02 12:33:58

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

$ php -v

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

$ brew install homebrew/php/php71

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

$ php -v

现在你在终端中看到当前的 php 版本....谢谢

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

$ 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,

$ brew install homebrew/php/php71

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

$ php -v

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

我很OK 2024-09-02 12:33:58

使用这个命令:

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

Use this Command:

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
舂唻埖巳落 2024-09-02 12:33:58

您可以使用curl来更新php版本。

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

最后一步:

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

检查升级版本

php -v

You can use curl to update php version.

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

Last Step:

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

Check the upgraded version

php -v
妳是的陽光 2024-09-02 12:33:58

最好的升级方法是
从源代码编译它

请参阅本教程,这可能对您有帮助

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

你丑哭了我 2024-09-02 12:33:58

将php7升级到最新稳定版本brew升级php7
或者对于 php5.X 到最新稳定版本,

brew upgrade php56

请使用 brew list 检查已安装的版本

to upgrade php7 to latest stable version brew upgrade php7
or for php5.X to latest stable version

brew upgrade php56

use brew list to check installed version

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文