PHP配置默认SSL CA证书,curl访问https地址错误cURL error 60
CA证书
可以在访问证书官网下载https://curl.haxx.se/docs/caextract.html,或直接点击下载地址: https://curl.haxx.se/ca/cacert.pem
将下载的证书pem文件保存到电脑任意目录中,复制目录地址。例如我保存在php目录下,可自行修改
开启php扩展
在php.ini中开启curl、openssl扩展。
extension=curl extension=openssl
在php.ini中[curl]和[openssl]修改curl.cainfo和openssl.cafile和openssl.capath,指向到保存的证书pem地址
[curl] ; A default value for the CURLOPT_CAINFO option. This is required to be an ; absolute path. curl.cainfo =D:\phpStudy2\PHPTutorial\php\cacert.pem [openssl] ; The location of a Certificate Authority (CA) file on the local filesystem ; to use when verifying the identity of SSL/TLS peers. Most users should ; not specify a value for this directive as PHP will attempt to use the ; OS-managed cert stores in its absence. If specified, this value may still ; be overridden on a per-stream basis via the "cafile" SSL stream context ; option. openssl.cafile=D:\phpStudy2\PHPTutorial\php\cacert.pem ; If openssl.cafile is not specified or if the CA file is not found, the ; directory pointed to by openssl.capath is searched for a suitable ; certificate. This value must be a correctly hashed certificate directory. ; Most users should not specify a value for this directive as PHP will ; attempt to use the OS-managed cert stores in its absence. If specified, ; this value may still be overridden on a per-stream basis via the "capath" ; SSL stream context option. openssl.capath=D:\phpStudy2\PHPTutorial\php
设置完毕,重启php服务
Appache SSL支持
如不行,可百度Appche SSL模块是否支持
发生情况
在使用GuzzleHttp爬虫的时候,抓取https时候报错
GuzzleHttp\Exception\RequestException : cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
本文作者: admin
本文链接: https://www.jianbaizhan.com/article/638
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!