Linux 系统安装OpenSSL 1.1.1版本
2019-08-01 15:56:21    991    0    0
admin

安装OpenSSL

  1. wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz
  2. tar zxvf openssl-1.1.1c.tar.gz
  3. cd openssl-1.1.1c
  4. ./config shared zlib --prefix=/usr/local/ssl

一定记得加上shared选项,不然重新编译php的openssl扩展的时候,OpenSSL Library Version和OpenSSL Header Version会不一致。用--prefix指定安装路径

  1. make && make install
  2. mv /usr/bin/openssl /usr/bin/openssl.bak
  3. mv /usr/include/openssl /usr/include/openssl.bak
  4. # ① 用find / -name openssl查询一下(如果PHP采用了--with-openssl=/usr/local/openssl选项来编译,一般和这个选项的值相同),所以也有可能是这个路径
  5. # mv /usr/local/openssl /usr/local/openssl.bak
  6. ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
  7. ln -s /usr/local/ssl/include/openssl /usr/include/openssl
  8. # 用find / -name openssl查询一下,也有可能是这个路径(同① )
  9. # ln -s /usr/local/ssl/include/openssl /usr/local/openssl
  10. echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
  11. ldconfig

查看openssl版本

  1. openssl version

升级PHP的OpenSSL扩展

OpenSSL未与PHP一起编译的情况下的升级

  1. 进入PHP源码中的openssl扩展文件夹
  1. cd /root/lnmp/src/php-7.2.20/ext/openssl
  1. 准备config.m4文件
  1. cp config0.m4 config.m4
  1. 执行phpize

通过命令which phpize找到phpize路径,比如我找到的路径为/usr/bin/phpize,则执行

  1. /usr/bin/phpize
  1. 生成配置

通过命令which php-configfind / -name php-config找到php-config路径,比如我找到的路径为/usr/local/php/bin/php-config,则执行

  1. ./configure --with-openssl=/usr/local/ssl --with-php-config=/usr/local/php/bin/php-config
  1. 安装
  1. make && make install
  1. 启用扩展
    在php.ini配置文件中添加:
  1. 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版本

  1. php -v

获取php编译时的参数

  1. php -i | grep Command
  2. #'./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安装路径在上面提到了

  1. cd /root/lnmp/src/php-7.2.20
  2. ./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
  3. make && make install

这里我把--with-openssl=/usr/local/openssl中的/usr/local/openssl改成了新版本的路径/usr/local/ssl

查看OpenSSL扩展版本

  1. php -i | grep OpenSSL

你采用的是和之前源码安装一样的版本库无非就是重新编译一次需要点时间,其他都不需要修改就可以安装对openssl的升级了。我们重启下php-fpm服务。

  1. service php-fpm restart

然后我们去phpinfo()函数输出里面去找找openssl的版本是否匹配,是的话就证明操作成功了。

Prev: Docker容器的创建、启动、和停止

Next: Twig模版语言入门

991
Table of content