使用 OpenSSL 编译 PHP 7.2
Compiling PHP 7.2 with OpenSSL
我正在尝试在 RedHat 操作系统上编译 PHP 7.2.5
。我已经在我自己的目录 /home/user/openssl-1.1
中自己编译了 OpenSSL 1.1.0h
。这些是我如何编译 OpenSSL
的行
TARGET_DIR=/home/usr/openssl-1.1
# ...
./config no-shared --prefix=${TARGET_DIR} --openssldir=${TARGET_DIR}/conf
make INSTALL_PREFIX=${TARGET_DIR}
make install
现在,我想将 PHP 7.2.5
连同已编译的 OpenSSL 版本一起编译。我用这些行来做:
PHP_PREFIX=/home/user/php-7.2
export OPENSSL_INCLUDE_DIR=/home/user/openssl-1.1/include/openssl
# ...
./buildconf --force
./configure --prefix="$PHP_PREFIX" \
--enable-sockets \
--enable-embed \
--enable-com-dotnet \
--enable-ctype \
--with-curl \
--enable-mbstring=static \
--with-gd \
--enable-soap \
--enable-pdo=static \
--with-mp \
--with-curl=static \
--with-openssl=static \
--with-openssl-dir="/home/user/openssl-1.1"
但在某些时候,我收到此错误消息:
configure: error: Cannot find OpenSSL's <evp.h>
此文件 evp.h
存在于目录 /home/user/openssl-1.1/include/openssl
。
有谁知道如何解决这个问题?
我找到了 这个 问题的解决方案:必须将两个参数 --with-openssl
和 --with-libdir
更改为如下内容:
./buildconf --force
./configure --prefix="$PHP_PREFIX" \
# ...
--with-openssl=/home/user/openssl-1.1 \
--with-libdir=lib64
据我所知,这里不需要其他环境变量。
我已经用 PHP 7.2 和 7.4
进行了测试
考虑调整PKG_CONFIG_PATH环境变量,如果你在非标准前缀中安装软件,将其指向OpenSSL的pkgconfig目录。
程序:
- 安装 OpenSSL
wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar xzf /root/tmp/openssl/openssl-1.1.1i.tar.gz
cd openssl-1.1.1i
./Configure --prefix=/opt/openssl-1.1.1i/bin -fPIC -shared linux-x86_64
make -j 8
make install
- 导出变量PKG_CONFIG_PATH指向pkgconfig目录
export PKG_CONFIG_PATH=/opt/openssl-1.1.1i/bin/lib/pkgconfig
- 编译安装PHP.
tar xzf php-7.4.13.tar.gz
cd php-7.4.13
./configure --prefix=/opt/php-7.4.13 --with-curl --enable-exif \
--with-mhash --enable-mbstring --with-mysqli --enable-mysqlnd \
--with-zlib --with-bz2 --enable-fpm --with-pear -enable-gd\
--with-apxs2=/opt/httpd-2.4.46/bin/apxs - --with-webp \
--with-jpeg --with-xpm --with-freetype --enable-intl \
--disable-ipv6 --with-pgsql --without-sqlite3 --without-pdo-sqlite \
--disable-cgi --enable-soap --without-imap --without-imap-ssl \
--with-openssl=/opt/openssl-1.1.1i/bin \
--with-openssl-dir=/opt/openssl-1.1.1i/bin
make -j 8
make install
- 测试 OpenSSL 版本
/opt/php-7.4.13/bin/php -i | grep -i openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.1.1i 8 Dec 2020
OpenSSL Header Version => OpenSSL 1.1.1i 8 Dec 2020
Openssl default config => /opt/openssl-1.1.1i/bin/ssl/openssl.cnf
我正在尝试在 RedHat 操作系统上编译 PHP 7.2.5
。我已经在我自己的目录 /home/user/openssl-1.1
中自己编译了 OpenSSL 1.1.0h
。这些是我如何编译 OpenSSL
TARGET_DIR=/home/usr/openssl-1.1
# ...
./config no-shared --prefix=${TARGET_DIR} --openssldir=${TARGET_DIR}/conf
make INSTALL_PREFIX=${TARGET_DIR}
make install
现在,我想将 PHP 7.2.5
连同已编译的 OpenSSL 版本一起编译。我用这些行来做:
PHP_PREFIX=/home/user/php-7.2
export OPENSSL_INCLUDE_DIR=/home/user/openssl-1.1/include/openssl
# ...
./buildconf --force
./configure --prefix="$PHP_PREFIX" \
--enable-sockets \
--enable-embed \
--enable-com-dotnet \
--enable-ctype \
--with-curl \
--enable-mbstring=static \
--with-gd \
--enable-soap \
--enable-pdo=static \
--with-mp \
--with-curl=static \
--with-openssl=static \
--with-openssl-dir="/home/user/openssl-1.1"
但在某些时候,我收到此错误消息:
configure: error: Cannot find OpenSSL's <evp.h>
此文件 evp.h
存在于目录 /home/user/openssl-1.1/include/openssl
。
有谁知道如何解决这个问题?
我找到了 这个 问题的解决方案:必须将两个参数 --with-openssl
和 --with-libdir
更改为如下内容:
./buildconf --force
./configure --prefix="$PHP_PREFIX" \
# ...
--with-openssl=/home/user/openssl-1.1 \
--with-libdir=lib64
据我所知,这里不需要其他环境变量。
我已经用 PHP 7.2 和 7.4
进行了测试考虑调整PKG_CONFIG_PATH环境变量,如果你在非标准前缀中安装软件,将其指向OpenSSL的pkgconfig目录。
程序:
- 安装 OpenSSL
wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar xzf /root/tmp/openssl/openssl-1.1.1i.tar.gz
cd openssl-1.1.1i
./Configure --prefix=/opt/openssl-1.1.1i/bin -fPIC -shared linux-x86_64
make -j 8
make install
- 导出变量PKG_CONFIG_PATH指向pkgconfig目录
export PKG_CONFIG_PATH=/opt/openssl-1.1.1i/bin/lib/pkgconfig
- 编译安装PHP.
tar xzf php-7.4.13.tar.gz
cd php-7.4.13
./configure --prefix=/opt/php-7.4.13 --with-curl --enable-exif \
--with-mhash --enable-mbstring --with-mysqli --enable-mysqlnd \
--with-zlib --with-bz2 --enable-fpm --with-pear -enable-gd\
--with-apxs2=/opt/httpd-2.4.46/bin/apxs - --with-webp \
--with-jpeg --with-xpm --with-freetype --enable-intl \
--disable-ipv6 --with-pgsql --without-sqlite3 --without-pdo-sqlite \
--disable-cgi --enable-soap --without-imap --without-imap-ssl \
--with-openssl=/opt/openssl-1.1.1i/bin \
--with-openssl-dir=/opt/openssl-1.1.1i/bin
make -j 8
make install
- 测试 OpenSSL 版本
/opt/php-7.4.13/bin/php -i | grep -i openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.1.1i 8 Dec 2020
OpenSSL Header Version => OpenSSL 1.1.1i 8 Dec 2020
Openssl default config => /opt/openssl-1.1.1i/bin/ssl/openssl.cnf