简体   繁体   English

如何在 Mac OS X 中升级 PHP?

[英]How do I upgrade PHP in Mac OS X?

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. MacPorts 不会将 php 识别为已安装的软件包,因为它没有安装 PHP 本身。
  • Running locate php indicates there are probably many dependencies.运行locate php表明可能有很多依赖项。
  • 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.我不知道 php 是如何安装的,因为它包含在操作系统中,所以我不知道应该从源代码安装还是下载二进制文件。 I also don't know the proper way to uninstall the previous version without breaking dependencies.我也不知道在不破坏依赖关系的情况下卸载以前版本的正确方法。

I am running on Leopard.我在 Leopard 上运行。 I have a feeling Apple doesn't want you to upgrade.我有一种感觉,Apple 不想让您升级。 Would buying Snow Leopard and upgrade solve this problem (and future ones like it)?购买 Snow Leopard 并升级会解决这个问题(以及未来的类似问题)吗?

You may want to check out Marc Liyanage's PHP package.您可能想查看 Marc Liyanage 的 PHP 包。 It comes in a nice Mac OS X installer package that you can double-click.它带有一个很好的 Mac OS X 安装程序包,您可以双击它。 He keeps it pretty up to date.他保持最新状态。

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.此外,虽然升级到 Snow Leopard 不会帮助您在未来进行 PHP 更新,但它可能会为您提供更新版本的 PHP。 I'm running OS X 10.6.2 and it has PHP 5.3.0.我运行的是 OS X 10.6.2,它有 PHP 5.3.0。

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_profile or .bashrc然后在你的.bash_profile.bashrc配置

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

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 -rf into 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.就像我说的,这是我认为的一种简单方法。

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.您仍然可以使用 MacPorts 安装它。 sudo port install php52 (or whichever version you want) will install PHP. sudo port install php52 (或您想要的任何版本)将安装 PHP。

It won't overwrite the Apple-supplied version.它不会覆盖 Apple 提供的版本。 It'll install it under /opt/local .它将安装在/opt/local You can add /opt/local to the beginning of your $PATH , and use the MacPorts version in your Apache config.您可以将/opt/local添加到$PATH的开头,并在您的 Apache 配置中使用 MacPorts 版本。

Option #1选项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.这不会覆盖系统上 PHP 的基本版本,而是将其干净地安装在 /usr/local/php5 中。

Option #2选项#2

My preferred method is to just install via Homebrew .我的首选方法是通过 Homebrew 安装

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) .在我继续之前,我有OS X Server的最新版本 (v5.0.15) (是的,太可怕了,我知道……但是,Web 服务器似乎工作正常) I searched high and low for days trying to update (or at least get Apache to point to) a new version of PHP.我搜索了好几天试图更新(或至少让 Apache 指向)新版本的 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 ) .我的mcrypt和其他扩展一起不起作用,我从http://php-osx.liip.ch/和其他教程无数次安装和重新安装 PHP 直到我终于注意到在评论中写的一点信息在 OS X Server 保留的许多不同.conf文件中,OS X Server 在加载 Apache httpd.conf (位于/etc/apache2/httpd.conf之前加载它自己的自定义.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) :然后添加正确的路径(如果您通过http://php-osx.liip.ch/链接安装,则应该已经安装了)

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

After this modification, my PHP finally loaded the correct PHP installation.经过这次修改,我的PHP终于加载了正确的PHP安装。 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.话虽如此,如果事情变得不稳定,那可能是因为 OS X 在安装 OS X 时就可以处理 PHP 的本机安装。 To revert, just undo the change above.要恢复,只需撤消上面的更改。

Anyway, hopefully this is helpful for anyone else spending countless hours on this.无论如何,希望这对其他人花费无数小时有帮助。

Upgrading to Snow Leopard won't solve the your primary problem of keeping PHP up to date.升级到 Snow Leopard 并不能解决保持 PHP 最新的主要问题。 Apple doesn't always keep the third party software that it bundles up to date with OS updates. Apple 并不总是将其捆绑的第三方软件与操作系统更新保持同步。 And relying on Apple to get you the bug fix / security update you need is asking for trouble.依靠 Apple 为您提供所需的错误修复/安全更新是自找麻烦。

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.此外,我建议通过 MacPorts 进行安装(并进行必要的配置以使用它而不是Apple 的 PHP),而不是尝试升级 Apple 提供的 PHP。 Anything you do to /usr/bin risks being overwritten by some future Apple update.你对/usr/bin所做的任何事情/usr/bin可能被未来的苹果更新覆盖。

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

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 版本....谢谢

使用这个命令:

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

You can use curl to update php version.您可以使用 curl 来更新 php 版本。

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

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 http://www.computersnyou.com/2012/09/how-to-upgrade-php-in-mac-osx-compiling.html

to upgrade php7 to latest stable version brew upgrade php7 or for php5.X to latest stable version将 php7 升级到最新的稳定版本brew upgrade php7或 php5.X brew upgrade php7到最新的稳定版本

brew upgrade php56

use brew list to check installed version使用brew list检查已安装的版本

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

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