You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法在macOS Big Sur(11)通过Homebrew安装PHP 8.2求助

在macOS 11(Big Sur)上安装PHP 8.2的问题与解决方案

问题描述

在运行macOS 11(Big Sur)的iMac上执行brew install php@8.2时,安装流程卡在openexr编译环节,具体报错信息如下:

==> Fetching openexr
==> Downloading https://raw.githubusercontent.com/Homebrew/homebrew-core/651ab1c
Already downloaded: /Users/dmitrij/Library/Caches/Homebrew/downloads/fbe1f966b03328ee5324e472eb2169424788a9688a45e5c07d93144adfb380af--openexr.rb
==> Downloading https://github.com/AcademySoftwareFoundation/openexr-images/raw/
Already downloaded: /Users/dmitrij/Library/Caches/Homebrew/downloads/ba0da2a31c9ecfc80347695d4b2135fbec9f60358d1029a5402cfffb64a38ebf--AllHalfValues.exr
==> Downloading https://github.com/AcademySoftwareFoundation/openexr/archive/ref
Already downloaded: /Users/dmitrij/Library/Caches/Homebrew/downloads/5c1b6fb3948c7430a5ed5806a0c7de2d4b01cec4546cb212611e6842e61e7eca--openexr-3.2.4.tar.gz
==> cmake ..
/Users/dmitrij/Library/Logs/Homebrew/openexr/01.cmake的最后15行内容:
-- Using Imath from /usr/local/lib/cmake/Imath
-- Performing Test OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN
-- Performing Test OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN - Success
-- Performing Test OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
-- Performing Test OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX - Success
-- Looking for include file ucontext.h
-- Looking for include file ucontext.h - not found
-- OpenEXR pkg-config generation enabled
-- Configure OpenEXR 3.2.4, library API version: 31.3.2.4
-- Building OpenEXR libraries
-- Building OpenEXR tools
-- Building OpenEXR examples
-- clang-format not found.
-- Configuring incomplete, errors occurred!

同时收到官方提示:

不要向Homebrew/brew或Homebrew/homebrew-core报告此问题!
错误信息:您正在使用macOS 11,我们(及苹果)不再支持该旧版本,部分软件包编译失败属于预期情况。

已尝试重装Homebrew、执行brew update/brew upgrade/brew update-reset等操作,均无法解决问题。

解决方案

1. 降级openexr适配macOS 11

新版本openexr已不再支持macOS 11,可通过安装旧版本绕开依赖问题:

  • 安装支持macOS 11的openexr 3.1.x版本:
    brew install openexr@3.1
    
  • 将该版本设为全局默认:
    brew link openexr@3.1 --force --overwrite
    
  • 再次执行PHP 8.2安装命令:
    brew install php@8.2
    

2. 用php-build手动编译PHP 8.2

php-build是专门用于编译多版本PHP的工具,可脱离Homebrew的依赖限制:

  1. 安装编译依赖工具:
    brew install autoconf automake libtool pkg-config
    
  2. 克隆php-build仓库到本地:
    git clone https://github.com/php-build/php-build.git ~/.php-build
    
  3. 将php-build加入环境变量(以zsh为例):
    echo 'export PATH="$HOME/.php-build/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc
    
  4. 编译指定版本的PHP 8.2(替换8.2.20为你需要的具体版本号):
    php-build 8.2.20 ~/local/php82
    
  5. 将编译好的PHP加入环境变量:
    echo 'export PATH="$HOME/local/php82/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc
    

3. 使用Docker运行PHP 8.2

不想本地编译的话,Docker是更省心的替代方案:

  1. 安装适配macOS 11的Docker Desktop版本
  2. 拉取PHP 8.2官方镜像:
    docker pull php:8.2-fpm
    
  3. 启动容器并挂载本地项目目录(替换/path/to/your/project为你的实际项目路径):
    docker run -d -v /path/to/your/project:/var/www/html -p 9000:9000 php:8.2-fpm
    

4. 通过MacPorts安装PHP 8.2

MacPorts对旧版本macOS的兼容性更好:

  1. 安装适配macOS 11的MacPorts版本
  2. 更新端口库:
    sudo port selfupdate
    
  3. 安装PHP 8.2:
    sudo port install php82
    
  4. 设置为默认PHP版本:
    sudo port select --set php php82
    

内容的提问来源于stack exchange,提问作者ViktorKK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 13:55:04