安装OpenSSL
wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz
tar zxvf openssl-1.1.1c.tar.gz
cd openssl-1.1.1c
./config shared zlib --prefix=/usr/local/ssl
一定记得加上shared选项,不然重新编译php的openssl扩展的时候,OpenSSL Library Version和OpenSSL Header Version会不一致。用--prefix
指定安装路径
make && make install
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
# ① 用find / -name openssl查询一下(如果PHP采用了--with-openssl=/usr/local/openssl选项来编译,一般和这个选项的值相同),所以也有可能是这个路径
# mv /usr/local/openssl /usr/local/openssl.bak
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
# 用find / -name openssl查询一下,也有可能是这个路径(同① )
# ln -s /usr/local/ssl/include/openssl /usr/local/openssl
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
ldconfig
查看openssl版本
openssl version
升级PHP的OpenSSL扩展
OpenSSL未与PHP一起编译的情况下的升级
- 进入PHP源码中的openssl扩展文件夹
cd /root/lnmp/src/php-7.2.20/ext/openssl
- 准备
config.m4
文件
cp config0.m4 config.m4
- 执行phpize
通过命令which phpize
找到phpize路径,比如我找到的路径为/usr/bin/phpize
,则执行
/usr/bin/phpize
- 生成配置
通过命令which php-config
或find / -name php-config
找到php-config路径,比如我找到的路径为/usr/local/php/bin/php-config
,则执行
./configure --with-openssl=/usr/local/ssl --with-php-config=/usr/local/php/bin/php-config
- 安装
make && make install
- 启用扩展
在php.ini配置文件中添加:
extension = "openssl.so"
重新编译php的时候注意事项
linux升级openssl后,重新编译php的openssl扩展后仍然不是最新版本
解决办法:
./configure
的时候 --with-openssl=/usr/local/ssl
一定要指定刚才装的路径,否则php的openssl还会是之前的版本
OpenSSL与PHP一起编译的情况下的升级
与php一同设置的编译参数情况
如果你和我一样很久很久以前安装了php的版本,而且又是在编译php版本的时候直接使用“–-with-openssl”的话,似乎也没有添加什么路径的话,那么你现在可能需要重新编译你的php版本了,首先我们要获取到当时编译php的参数,注意你的php源码版本要一致哦,当然你可以重新升级你的php版本也无妨(如果你选择升级php版本可能会导致你安装的一些组件无法使用,或者在启动php-fpm时候会有错误提示,我还是不太建议大家升级php版本,最好是找当前版本一直的源码进行重新编译)。
查看php版本
php -v
获取php编译时的参数
php -i | grep Command
#'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/etc/php.d' '--with-fpm-user=www' '--with-fpm-group=www' '--enable-fpm' '--enable-opcache' '--disable-fileinfo' '--enable-mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir=/usr/local' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-exif' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl=/usr/local/curl' '--enable-mbregex' '--enable-mbstring' '--with-password-argon2' '--with-sodium=/usr/local' '--with-gd' '--with-openssl=/usr/local/openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-ftp' '--enable-intl' '--with-xsl' '--with-gettext' '--enable-zip' '--enable-soap' '--disable-debug'
注意把这些“’”都去掉,因为我们采用了源码升级OpenSSL的方式,所以新的OpenSSL安装路径在上面提到了
cd /root/lnmp/src/php-7.2.20
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache --disable-fileinfo --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --with-gd --with-openssl=/usr/local/ssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --enable-soap --disable-debug
make && make install
这里我把--with-openssl=/usr/local/openssl
中的/usr/local/openssl
改成了新版本的路径/usr/local/ssl
查看OpenSSL扩展版本
php -i | grep OpenSSL
你采用的是和之前源码安装一样的版本库无非就是重新编译一次需要点时间,其他都不需要修改就可以安装对openssl的升级了。我们重启下php-fpm服务。
service php-fpm restart
然后我们去phpinfo()函数输出里面去找找openssl的版本是否匹配,是的话就证明操作成功了。