最近因为centos停止维护,遂迁移系统的时候,优先考虑使用ubuntu22.04,alibaba cloud 3以及openeurl22.03系统,旧项目因为没人维护,所以环境还是用的php5.6,结果在新系统上编译安装php5.6的时候,表面看着一切正常,实际在使用中php程序在调用curl扩展去访问https站点(比如微信接口)的时候,会出现502错误,导致系统无法使用。

开始排查,感觉应该是openssl版本问题,重新编译openssl,并在php5.6编译的时候,指定对应的openssl版本进行编译,
使用高版本系统安装低版本php出现curl请求异常的解决办法_运维
结果尝试各种版本,要嘛无法安装成功,直接报错,要嘛可以安装成功,但是同样在程序使用curl的时候报错

经过研究,发现是由于curl对应的openssl版本太高导致的,curl调用的openssl跟安装php时候,编译参数里面使用的–with-openssl并没有关系,通过phpinfo查看curl扩展的时候,在curl模块中,有个ssl version是指定了curl使用的openssl版本的

使用高版本系统安装低版本php出现curl请求异常的解决办法_运维_02

于是决定重新编译一个curl,并指定使用openssl,j结果也是编译不成功,通过检查以前centos7下正常服务器的配置发现,发现旧版的curl扩展ssl vsersion都是使用nss,于是改变方式,重新编译curl的时候,指定ssl为nss,然后再通过扩展的方式安装进去,经过测试,总算是成功解决该问题

使用高版本系统安装低版本php出现curl请求异常的解决办法_运维_03使用高版本系统安装低版本php出现curl请求异常的解决办法_运维_04

整理步骤如下:

#重新编译php5.6.40,先不添加curl扩展,去掉--with-curl 参数,后续再单独添加curl扩展
cd php-5.6.40/
./configure --prefix=/usr/local/webserver/php5.6 --with-config-file-path=/usr/local/webserver/php5.6/etc --enable-fpm --with-zlib --with-openssl --with-mhash --enable-bcmath --enable-mbstring --with-mysql --with-mysqli --with-gd --enable-gd-native-ttf --enable-soap --with-jpeg-dir --with-freetype-dir --with-png-dir --enable-sockets --with-openssl
make ZEND_EXTRA_LIBS='-liconv'
make install

#下载并安装curl到指定目录,安装完成后,curl7.62版本,被单独安装到了/usr/local/curl7.62目录
cd curl-7.62.0
./configure --prefix=/usr/local/curl7.62 -with-nss
make
make install

#进入php5.4对应的安装包下的ext/curl目录
#cd ../php-5.6.40/ext/curl/
/usr/local/webserver/php5.6/bin/phpize
./configure --prefix=/usr/local/curl7.62 -with-nss
make 
make install
 
#安装完后,添加对应的扩展到php.ini
vi /usr/local/webserver/php5.6/conf/php.ini
#添加下面配置
extension=curl.so

#重新reload或是重启下php
/etc/init.d/php-fpm56 restart
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.