当前位置:首页 > PHP > 正文内容

PHP 5.6上的SSL证书验证

高老师6年前 (2020-10-31)PHP1282

我最近将本地OS X Zend Server安装更新为PHP 5.6,并且在运行composer self-update时收到以下错误消息:

[Composer\Downloader\TransportException]                                                                                       
The "https://getcomposer.org/version" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:  
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed                                              
Failed to enable crypto                                                                                                        
failed to open stream: operation failed

到处搜寻,我终于得出结论,PHP 5.6中对SSL进行了各种改进,问题是它在我的系统上找不到任何OpenSSL证书。这并不完全令人惊讶,因为OS X不再使用内部使用OpenSSL而是使用其自己的库。

有一个新的PHP函数openssl_get_cert_locations对此有所帮助,因此我运行了:

 php -r "print_r(openssl_get_cert_locations());"

输出信息:

Array
(
    [default_cert_file] => /usr/local/openssl-0.9.8zb/ssl/cert.pem
    [default_cert_file_env] => SSL_CERT_FILE
    [default_cert_dir] => /usr/local/openssl-0.9.8zb/ssl/certs
    [default_cert_dir_env] => SSL_CERT_DIR
    [default_private_dir] => /usr/local/openssl-0.9.8zb/ssl/private
    [default_default_cert_area] => /usr/local/openssl-0.9.8zb/ssl
    [ini_cafile] => 
    [ini_capath] => 
)

我的系统上没有目录/usr/local/openssl-0.9.8zb,并且没有定义SSL_CERT_FILESSL_CERT_DIR,因此报错也就不足为奇了。

要修复它,我通过自制软件安装openssl:

brew install openssl

这会将openssl证书安装到/usr/local/etc/openssl/cert.pem,因此我们现在可以使用新的PHP 5.6 INI设置openssl.cafile告诉PHP在哪里可以找到证书:

php.ini配置如下:

openssl.cafile=/usr/local/etc/openssl/cert.pem

扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/176.html

分享给朋友:

“PHP 5.6上的SSL证书验证” 的相关文章

PHP可变变量的作用

PHP可变变量的作用

<!doctype html> <html> <head> <meta charset="utf-8"> <title>demo</title> </head> <bod...

PHP生成缩略图

PHP生成缩略图

//参数1  文件名    参数2  缩放比例  function   _thumb($_filename,$_percent){    ob_clean();...

php非对称加密

php非对称加密

先在centos安装openssl,然后开始://生成私钥openssl genrsa -out rsa_private_key.pem 1024//生成公钥openssl rsa -in rsa_private_key.pem&...

php代理下载,php代下载文件,php下载远程文件,php远程文件下载

php代理下载,php代下载文件,php下载远程文件,php远程文件下载

经常我们下载国外资源容易被墙,可以通过php脚本获取远程文件流然后输出给我们的浏览器来下载。<?php //设置下载文件的url $url = 'https://mirrors.huaweicloud.com/ubuntukylin/ubuntukylin-19....

php redis事务

php redis事务

概念请参考w3school文章: redis watch ,redis exec (看完基本秒懂)(1)基本事务://连接本地的 Redis 服务 $redis = new Redis(); $redis->con...

tp orm事务提交未执行的教训和总结

tp orm事务提交未执行的教训和总结

最近在项目中处理一个关于商品数据重复需要删除多余的商品记录,但是删除一条商品必然要把关联的其他表商品的id和其他商品信息更换为正确的,删除一个商品记录,同时要去修改100多张表的关联商品数据,在项目中引用了tp orm 1.2版本,由于项目是php5.6版本,没法使用最新orm,在代码中每处理1个商...