macOS High Sierra使用Homebrew安装PHP触发编译报错问题咨询
问题场景
在搭载 macOS High Sierra 系统的设备上通过 Homebrew 执行 brew install php 命令安装 PHP 时,出现如下编译报错:
clang -I. -Iinclude -fPIC -arch x86_64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/usr/local/etc/openssl@1.1\"" -DENGINESDIR="\"/usr/local/Cellar/openssl@1.1/1.1.1l/lib/engines-1.1\"" -D_REENTRANT -DNDEBUG -MMD -MF crypto/rand/rand_unix.d.tmp -MT crypto/rand/rand_unix.o -c -o crypto/rand/rand_unix.o crypto/rand/rand_unix.c In file included from crypto/rand/rand_unix.c:38: /usr/include/CommonCrypto/CommonRandom.h:35:9: error: unknown type name 'CCCryptorStatus' typedef CCCryptorStatus CCRNGStatus; ^ crypto/rand/rand_unix.c:385:47: error: use of undeclared identifier 'kCCSuccess' if (CCRandomGenerateBytes(buf, buflen) == kCCSuccess) ^ 2 errors generated. make[1]: *** [crypto/rand/rand_unix.o] Error 1 make[1]: *** Waiting for unfinished jobs.... make: *** [all] Error 2 Do not report this issue to Homebrew/brew or Homebrew/core!
问题原因
- 核心冲突为Homebrew 官方默认源的最新 openssl@1.1 依赖包和 macOS High Sierra 系统自带的 CommonCrypto 库版本不兼容:High Sierra 自带的 CommonCrypto 框架版本过低,缺少 openssl@1.1.1l 及以上版本编译所需的
CCCryptorStatus类型定义、kCCSuccess常量等符号。 - Homebrew 官方已停止对 macOS High Sierra(10.13)这类老旧系统的支持,默认的公式包没有做旧系统兼容适配,直接安装默认版本 PHP 会触发依赖编译失败。
可行解决方法
方法一:安装适配旧系统的 openssl 版本后再安装 PHP
- 先卸载当前不兼容的 openssl@1.1 包:
brew uninstall --ignore-dependencies openssl@1.1 - 安装适配 High Sierra 的 openssl@1.1 历史版本:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8b9d6d688f483a0f33fcfc93d433de5017ebc23a/Formula/openssl@1.1.rb - 锁定 openssl 版本避免后续自动升级破坏兼容性:
brew pin openssl@1.1 - 重新执行 PHP 安装命令即可:
brew install php
方法二:使用适配旧 macOS 版本的第三方 PHP 源
- 添加专门适配老旧 macOS 系统的 PHP 源:
brew tap shivammathur/php - 直接从该源安装对应适配版本的 PHP,例如安装 PHP7.4 可执行:
brew install shivammathur/php/php@7.4,可按需选择支持的 PHP 版本。
方法三:临时指定编译头文件路径
如果仅需要临时安装,可在安装前指定环境变量优先调用系统头文件:CPPFLAGS="-I/usr/include" brew install php
内容的提问来源于stack exchange,提问作者Maxime Roche
相关产品推荐
相关产品推荐

