简体   繁体   English

自制软件 - 升级 php 破坏了 php 5.6 依赖

[英]homebrew - upgrade php broke php 5.6 dependency

I have multiple versions of PHP installed on my localhost using homebrew:我使用自制软件在我的本地主机上安装了多个版本的 PHP:

  • the standard core php package (v7.3.12)标准核心 php 包 (v7.3.12)
  • php 5.6 from exolnet/homebrew-deprecated php 5.6 from exolnet/homebrew-deprecated

Now when I upgraded php to 7.3.12 recently it upgraded a dependency that php@5.6 requires and now I am getting this error:现在,当我最近将 php 升级到 7.3.12 时,它升级了 php@5.6 所需的依赖项,现在我收到此错误:

dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
  Referenced from: /usr/local/Cellar/php@5.6/5.6.40/bin/./php
  Reason: image not found
[1]    83775 abort      ./php

And when I navigate to /usr/local/opt/openssl/lib/ I see that I now have the upgraded libcrypto.1.1.dylib installed.当我导航到/usr/local/opt/openssl/lib/我看到我现在已经安装了升级的libcrypto.1.1.dylib

I've tried brew upgrade and reinstalling php@5.6 but no joy.我试过brew upgrade并重新安装 php@5.6 但没有任何乐趣。

Does anyone have a suggestion?有人有建议吗? I really need both versions of php working on my localhost to continue development.我真的需要在我的本地主机上运行两个版本的 php 才能继续开发。

From my experience, trying to manage multiple PHP versions via homebrew is an absolute PITA, and I don't think I've ever got to the point where I can easily have both versions available side by side (until now!).根据我的经验,尝试通过自制软件管理多个 PHP 版本是绝对的 PI​​TA,而且我认为我还没有达到可以轻松并排使用两个版本的地步(直到现在!)。 Extensions are also supported, the details of which are provided later on in this answer.还支持扩展,稍后在本答案中提供了扩展的详细信息。

That said, I have found a guide that gives some instructions on how to get this working and it works an absolute treat:也就是说, 我找到了一个指南,其中提供了一些有关如何使其工作的说明,并且它绝对有效:

The linked guide references this method in the context of running PHP within Apache, so if that's your use case that's a nice little bonus for you too.链接指南在 Apache 中运行 PHP 的上下文中引用了此方法,因此如果这是您的用例,那对您来说也是一个不错的小奖励。

Now, because just posting links as answers on StackOverflow just isn't the done thing, I've detailed the main steps you need to follow in order below.现在,因为仅仅在 StackOverflow 上发布链接作为答案还不是完成的事情,我已经按照下面的顺序详细介绍了您需要遵循的主要步骤。 Homebrew uses different paths on Apple Silicon hardware vs Intel because of course it does, so if I've missed any path changes please let me know so I can update my answer. Homebrew 在 Apple Silicon 硬件和 Intel 上使用不同的路径,因为它当然可以,所以如果我错过了任何路径更改,请告诉我,以便我可以更新我的答案。

For anyone following this guide that doesn't yet have the prerequisites installed, ensure you have the Xcode command line tools and Homebrew installed and up to date.对于遵循本指南但尚未安装先决条件的任何人,请确保您已安装 Xcode 命令行工具和 Homebrew 并且是最新的。

If you want to check Homebrew for any issues, you can run如果你想检查 Homebrew 是否有任何问题,你可以运行

brew doctor

It's also never a bad idea to ensure that you have OpenSSL installed, especially if starting a fresh on macOS Monterey:确保您已安装 OpenSSL 也绝不是一个坏主意,尤其是在 macOS Monterey 上重新开始时:

brew install openssl

So, let's get started.那么,让我们开始吧。

Reset your environment重置环境

First, update everything then upgrade:首先,更新所有内容然后升级:

brew update
brew upgrade
brew cleanup

The reason for this is: "This will actually 'migrate' the core PHP packages (which are the only ones supported), but there's a bunch of symlinks utilized that could cause problems down the road, so after upgrading, we'll remove all PHP packages, to provide a fresh start"这样做的原因是:“这实际上会‘迁移’核心 PHP 包(这是唯一受支持的包),但是使用了一堆符号链接可能会导致问题,因此升级后,我们将删除所有PHP 包,提供一个全新的开始”

Once you've done that, check what's actually installed:完成后,检查实际安装的内容:

brew list | grep php

Then remove whatever you find, for example:然后删除您找到的任何内容,例如:

brew uninstall --force php56 php56-apcu php56-opcache php56-xdebug
brew uninstall --force php70 php70-apcu php70-opcache php70-xdebug
brew uninstall --force php71 php71-apcu php71-opcache php71-xdebug
brew uninstall --force php72 php72-apcu php72-opcache php72-xdebug
brew cleanup

Double check there's nothing left:仔细检查没有什么剩下的:

brew list | grep php

and clean up any old configuration files:并清理所有旧的配置文件:

Intel:英特尔:

rm -Rf /usr/local/etc/php/*

Apple Silicon:苹果硅:

rm -Rf /opt/homebrew/etc/php/*

If have the exolnet/deprecated tap installed, you'll need to remove it first using如果安装了exolnet/deprecated tap,您需要先使用

brew untap exolnet/deprecated

If you don't, you can get some weird conflicts如果你不这样做,你会得到一些奇怪的冲突

Add the new Tap and Install添加新的 Tap and Install

We're then going to tap a different repository .然后我们将点击一个不同的存储库 This repository has many versions of PHP pre-built which may or may not work for you, however installation should be much faster as we don't have to compile from source.这个存储库有许多预先构建的 PHP 版本,它们可能适合你,也可能不适合你,但是安装应该快得多,因为我们不必从源代码编译。

brew tap shivammathur/php

You can then install any PHP versions you require:然后,您可以安装所需的任何 PHP 版本:

brew install shivammathur/php/php@7.0
brew install shivammathur/php/php@7.1
brew install shivammathur/php/php@7.2
brew install shivammathur/php/php@7.3
brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@8.0

At the time of writing, this repository has versions 5.6 through 8.1 available for installation在撰写本文时,此存储库有 5.6 到 8.1 版本可供安装

The php.ini files are located in the following directories: php.ini文件位于以下目录中:

Intel:英特尔:

/usr/local/etc/php/7.0/php.ini
/usr/local/etc/php/7.1/php.ini
/usr/local/etc/php/7.2/php.ini
/usr/local/etc/php/7.3/php.ini
/usr/local/etc/php/7.4/php.ini
/usr/local/etc/php/8.0/php.ini

Apple Silicon:苹果硅:

/opt/homebrew/etc/php/7.0/php.ini
/opt/homebrew/etc/php/7.1/php.ini
/opt/homebrew/etc/php/7.2/php.ini
/opt/homebrew/etc/php/7.3/php.ini
/opt/homebrew/etc/php/7.4/php.ini
/opt/homebrew/etc/php/8.0/php.ini

Link your desired version链接您想要的版本

Once you've got here, close and reopen any terminal windows you have open to avoid strange path issues.到达此处后,关闭并重新打开您打开的所有终端窗口,以避免出现奇怪的路径问题。

Now, these versions are installed, but not linked.现在,这些版本的安装位置,但没有联系。 To switch to PHP 7.3 for example, run the following command:例如,要切换到 PHP 7.3,请运行以下命令:

brew unlink php && brew link --overwrite --force php@7.3

And then check we have the correct version:然后检查我们有正确的版本:

php -v

If we want to switch to PHP 7.4:如果我们想切换到 PHP 7.4:

brew unlink php && brew link --overwrite --force php@7.4

And then check we have the correct version:然后检查我们有正确的版本:

php -v

Easier Switching更容易切换

If you want a faster way of switching PHP versions, check out the sPHP script from rhukster如果你想切换PHP版本更快的方法, 检查出sPHP脚本rhukster

You can install this by running:您可以通过运行来安装它:

Intel:英特尔:

curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw/791fda77946ab2dbd053d7f27e9237aaf7392c4b/sphp.sh > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp

Apple Silicon:苹果硅:

curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw/791fda77946ab2dbd053d7f27e9237aaf7392c4b/sphp.sh > /opt/homebrew/bin/sphp
chmod +x /opt/homebrew/bin/sphp

and execute it using:并使用以下命令执行它:

sphp 8.0

Of course, with anything like this YMMV, but this should hopefully be a good starting point and actually get you where you need to be and remove some headaches.当然,像这样的 YMMV,但这应该是一个很好的起点,实际上可以让你到达你需要去的地方并消除一些麻烦。

What about extensions?扩展名呢?

Well I'm glad you asked.我很高兴你问。 For the later versions, pecl does work.对于更高版本, pecl 确实有效。 However, if you want to install xdebug for 5.6 for example, pecl throws its toys out of its pram.但是,例如,如果您想为 5.6 安装 xdebug,pecl 会将其玩具扔出婴儿车。

There is another repository you can tap, specifically for extensions:您可以点击另一个存储库,专门用于扩展:

brew tap shivammathur/php

Once you've done this, it's as simple as running:完成此操作后,就像运行一样简单:

brew install xdebug@5.6
brew install xdebug@8.1

The list of available extensions is detailed in the link above.可用扩展列表在上面的链接中有详细说明。 I won't include them here because it's a dynamic list and it'll soon be out of date, but most of them support 5.6 through to 8.1我不会在这里包括它们,因为它是一个动态列表,很快就会过时,但它们中的大多数都支持 5.6 到 8.1

Wrap up包起来

Having followed this process myself, this is the easiest approach I'm yet to find for managing multiple PHP versions on macOS.我自己遵循了这个过程,这是我在 macOS 上管理多个 PHP 版本的最简单的方法。 Feel free to run brew doctor and brew cleanup at any points during the process, it can't hurt after all and might in fact help with debugging any issues you happen across.在此过程中的任何时候都可以随意运行brew doctorbrew cleanup ,毕竟它不会受到伤害,实际上可能有助于调试您遇到的任何问题。 That said, my environment was an absolute mess and this tidied it up in about ten minutes.也就是说,我的环境绝对是一团糟,这在大约十分钟内就整理好了。 The longest step in this process for me was updating Homebrew itself.对我来说,这个过程中最长的一步是更新 Homebrew 本身。

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

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