使用Composer时,报证书错误解决方法

使用composer安装插件时,有时会报类似以下的错误:

Unable to locate a valid CA certificate file. You must set a valid 'cafile' option.
A valid CA certificate file is required for SSL/TLS protection.
You can disable this error, at your own risk, by setting the 'disable-tls' option to true.
Unable to locate a valid CA certificate file. You must set a valid 'cafile' option.
A valid CA certificate file is required for SSL/TLS protection.
You can disable this error, at your own risk, by setting the 'disable-tls' option to true.

原因一般是本地证书过期了,或者composer根本就没找到你的证书在哪。

查看本地证书的位置

输入命令

php -r 'var_dump(openssl_get_cert_locations());'

找到有.pem的哪一项,就是证书所在的目录,如:/Applications/MAMP/Library/OpenSSL/cert.pem

设置composer

如果证书已过期,需下载新的证书替换旧的证书
输入以下命令

composer config --global cafile '/Applications/MAMP/Library/OpenSSL/cert.pem'
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容