在 CentOS 上使用 OpenSSL 重新编译 PHP

Recompile PHP with OpenSSL on CentOS

我已将 openssl 版本从 1.0.1e 升级到 1.02l,将 PHP 版本从 PHP 5.6 升级到 PHP 7.1.8 (PHP 使用 yum 安装)

问题是,PHP 仍然检测到 1.0.1e 的 openssl 版本,而我希望它更新到安装的最新 openssl 版本,即 1.0.2l

我想知道这里有哪些选项,我该如何告诉 PHP 使用最新安装的 openssl 版本?

我的发现告诉我唯一的方法是重新编译 PHP? (如果有人能告诉我是否还有其他方法,我将不胜感激)如果唯一的方法是重新编译,我需要有关如何进行的帮助吗?涉及的步骤是什么。根据我的理解,这是我认为我必须做的事情。

我在这里遗漏了什么吗?

** 更新 **

这是使用 yum

安装的 php 个扩展的列表
 php-bcmath                        x86_64       7.1.8-1.el7.remi             @remi-php71        94 k
 php-common                        x86_64       7.1.8-1.el7.remi             @remi-php71       7.9 M
 php-fedora-autoloader             noarch       0.2.1-2.el7                  @epel              14 k
 php-gd                            x86_64       7.1.8-1.el7.remi             @remi-php71       204 k
 php-intl                          x86_64       7.1.8-1.el7.remi             @remi-php71       947 k
 php-json                          x86_64       7.1.8-1.el7.remi             @remi-php71        80 k
 php-mbstring                      x86_64       7.1.8-1.el7.remi             @remi-php71       2.8 M
 php-mysqlnd                       x86_64       7.1.8-1.el7.remi             @remi-php71       850 k
 php-pdo                           x86_64       7.1.8-1.el7.remi             @remi-php71       386 k
 php-pecl-zip                      x86_64       1.13.5-2.el7.remi.7.1        @remi-php71       175 k
 php-php-gettext                   noarch       1.0.12-1.el7                 @epel              57 k
 php-process                       x86_64       7.1.8-1.el7.remi             @remi-php71       180 k
 php-tcpdf                         noarch       6.2.13-1.el7                 @epel              11 M
 php-tcpdf-dejavu-sans-fonts       noarch       6.2.13-1.el7                 @epel             1.5 M
 php-tidy                          x86_64       7.1.8-1.el7.remi             @remi-php71       106 k
 php-xml                           x86_64       7.1.8-1.el7.remi             @remi-php71       851 k

我现在想配置 PHP 来使用这个扩展,到目前为止我已经想出了以下

./configure --with-openssl --with-openssl-dir=/usr/bin \
    --with-zlib \
    --enable-zip \
    --enable-xmlreader \
    --enable-xmlwriter \
    --enable-opcache \
    --enable-simplexml \
    --with-sqlite3 \
    --with-pdo-sqlite \
    --with-pdo-mysql=mysqlnd \
    --with-mysqli=mysqlnd \
    --with-mysql-sock=/var/lib/mysql/mysql.sock \
    --enable-mysqlnd \
    --with-mcrypt \
    --enable-mbstring \
    --enable-intl \
    --with-png-dir \
    --with-jpeg-dir \
    --enable-gd-native-ttf \
    --with-gd \
    --with-curl \
    --with-bz2 \
    --enable-bcmath

我现在只想知道,如果我需要启用上面列表中的任何扩展,我是使用 --enable 还是 --with ?例如,我如何启用 php-xml。我只使用 --enable-php-xml 吗?

是的,您需要下载 openssl (sources/headers) 的开发包,PHP 的源代码并使用以下键进行配置:

--with-openssl --with-openssl-dir=/usr/local/bin

根据PHP Manual > OpenSSL > Installing/Configuring

您可能还想使用其他键,例如 --with-curl=/usr/local--with-gd -- 请查看 PHP Manual > Appendices > Configure options and installation manuals for every module your want to compile it with like GD2 or Curl

上的文档

NOTE: You will need to download dev-packages of every module you are going to compile - it consumes noticable amount of time, plan accordingly.

NOTE 2: Keep in mind that all modules you are going to compile into your own build of PHP will be accessible through its functions (like image manipulation, https/curl requests etc), so it is highly recommended to use only stable and proven versions of modules not to add a new vulnerability to your web-site.

** 更新 **

./configure --with-openssl --with-openssl-dir=/usr/bin \
    --with-zlib=[DIR] \
    --enable-zip \
    --enable-opcache \
    --with-pdo-mysql=[DIR] \
    --with-mysqli=[DIR] \
    --with-mysql-sock=/var/lib/mysql/mysql.sock \
    --with-mcrypt=[DIR] \
    --enable-mbstring \
    --enable-intl \
    --with-png-dir=[DIR] \
    --with-jpeg-dir=[DIR] \
    --with-gd=[DIR] \
    --with-curl=[DIR] \
    --with-bz2=[DIR] \
    --enable-bcmath

[DIR] 可以自动发现,但我遇到了很多与 PHP 预期不同的情况。

xmlreaderxmlwritersimplexml 默认启用 PHP 5.1.2

从 PHP 5.3.0

开始默认启用

sqlite3pdo-sqlite

--enable-gd-native-ttf 从 PHP 5.5.0 开始被弃用,在 PHP 7.2.0.

中移除

您必须重新配置 PHP 构建过程。 yum 获得的软件中不能使用默认配置,必须在编译时指示系统使用特定版本的 SSL。

如果您已经安装了最新版本的 OpenSSL,您可以在编译 PHP.

之前转到您的 PHP 源代码并配置构建
./configure --with-openssl --with-openssl-dir=/usr/local/bin