php无法获取本地颁发者证书?

Windows版本

  1. https://curl.haxx.se/ca/cacert.pem 下载证书文件 cacert.pem,将其保存到 PHP 安装路径下。
  2. 编辑 php.ini 文件,删除 curl.cainfo 配置项前的分号注释符(;),值设置为保存的证书文件 cacert.pem 的绝对路径。
    20210707171649391.png
  3. 重启依赖 PHP 的服务。

linux版本解决方案

https://curl.haxx.se/docs/caextract.html 上下载cacert.pem

打开php.ini 搜索curl.cainfo 与 openssl.cafile,将其配置成你自己cacert.pem文件的路径
curl.cainfo='路径'
openssl.cafile='路径'

pecl channel-update pecl.php.net 
pear config-show
pear clear-cache
pear update-channels
pear upgrade

php -r "print_r(openssl_get_cert_locations());"
Array
(
    [default_cert_file] => /usr/lib/ssl/cert.pem
    [default_cert_file_env] => SSL_CERT_FILE
    [default_cert_dir] => /usr/lib/ssl/certs
    [default_cert_dir_env] => SSL_CERT_DIR
    [default_private_dir] => /usr/lib/ssl/private
    [default_default_cert_area] => /usr/lib/ssl
    [ini_cafile] =>
    [ini_capath] =>
)

wget http://curl.haxx.se/ca/cacert.pem && mv cacert.pem /usr/lib/ssl/cert.pem

php.ini
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo = /usr/lib/ssl/cert.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 = /usr/lib/ssl/cert.pem