PHP 安装错误 configure: error: Package requirements (openssl >= 1.0.

举报
林欣 发表于 2025/09/21 17:33:03 2025/09/21
【摘要】 configure: error: Package requirements (openssl >= 1.0.2) were not met:Requested 'openssl >= 1.0.2' but version of OpenSSL is 1.0.1eConsider adjusting the PKG_CONFIG_PATH environment variable if yo...
configure: error: Package requirements (openssl >= 1.0.2) were not met:

Requested 'openssl >= 1.0.2' but version of OpenSSL is 1.0.1e

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables OPENSSL_CFLAGS
and OPENSSL_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

这个错误表明你的系统安装的 OpenSSL 版本过低(1.0.1e),而 PHP 8 需要 OpenSSL ≥ 1.0.2。以下是解决方案:


方法 1:升级系统 OpenSSL(推荐)

1. 检查当前 OpenSSL 版本

openssl version

如果输出类似 OpenSSL 1.0.1e,说明版本过低。

2. 升级 OpenSSL

CentOS / RHEL

sudo yum remove openssl-devel openssl  # 卸载旧版本(可选)
sudo yum install -y epel-release
sudo yum install -y openssl11-devel openssl11  # 安装 OpenSSL 1.1.x

注意

  • CentOS 7 默认仓库可能没有 openssl11,需要启用 EPELSCL 仓库。
  • 如果 yum 找不到 openssl11,可以手动编译安装 OpenSSL 1.1.x(见方法 2)。

Ubuntu / Debian

sudo apt update
sudo apt install -y openssl libssl-dev  # 通常版本较新

如果默认仓库的 OpenSSL 仍然过低,可以手动编译安装(见方法 2)。


方法 2:手动编译安装 OpenSSL 1.1.x

如果系统仓库没有新版 OpenSSL,可以手动编译:

1. 下载并编译 OpenSSL

cd /usr/local/src
sudo wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz  # 最新稳定版
sudo tar -zxvf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
sudo ./config --prefix=/usr/local/openssl-1.1.1w --openssldir=/usr/local/openssl-1.1.1w
sudo make -j$(nproc)
sudo make install

2. 指定 PHP 编译时使用新 OpenSSL

在 PHP 的 ./configure 命令中,添加:

export OPENSSL_CFLAGS="-I/usr/local/openssl-1.1.1w/include"
export OPENSSL_LIBS="-L/usr/local/openssl-1.1.1w/lib -lssl -lcrypto"

然后重新运行 ./configure


方法 3:使用 --with-openssl 指定路径

如果 OpenSSL 安装在非标准路径(如 /usr/local/openssl-1.1.1w),可以在 PHP 配置时指定:

./configure \
    --with-openssl=/usr/local/openssl-1.1.1w \
    ...  # 其他配置

方法 4:降级 PHP 版本(不推荐)

如果无法升级 OpenSSL,可以安装 PHP 7.4(对 OpenSSL 1.0.1 兼容):

sudo yum install -y php74 php74-php-fpm  # CentOS/RHEL
sudo apt install -y php7.4 php7.4-fpm    # Ubuntu/Debian

验证 OpenSSL 版本

确保 PHP 编译时使用的是正确的 OpenSSL 版本:

/usr/local/php8/bin/php -i | grep "OpenSSL"

输出应类似:

OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.1.1w
OpenSSL Header Version => OpenSSL 1.1.1w

总结

方法 适用场景 备注
方法 1 系统仓库有新版 OpenSSL 最简单
方法 2 系统仓库无新版 OpenSSL 推荐手动编译
方法 3 OpenSSL 安装在非标准路径 适用于自定义安装
方法 4 无法升级 OpenSSL 降级 PHP(不推荐)

推荐顺序:方法 1 → 方法 2 → 方法 3
升级 OpenSSL 后,重新编译 PHP 即可解决问题。 🚀

【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。