windows下安装composer报错

今天在windows下安装composer,遇到一个奇怪的问题:

在执行

php -r "readfile('https://getcomposer.org/installer');" | php
的时候,报了这样一个错误
PHP Warning:  readfile(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in Command line code on line 1
PHP Warning:  readfile(): Failed to enable crypto in Command line code on line 1
PHP Warning:  readfile(https://getcomposer.org/installer): failed to open stream: operation failed in Command line code on line 1

后经过一番查找,发现是由于没有安装CA证书导致的,安装方法如下:

1.打开此网站https://curl.haxx.se/docs/caextract.html

2.点击cacert.pem,如果使用下载工具,会触发下载,如果直接在浏览器打开,会显示一大串乱七八糟的东西,完全复制它们,再新建一个cacert.pem文件,将复制的内容粘贴进去

3.将cacert.pem文件复制到[php的安装目录]\extras\openssl目录下,放到这里是为了方便管理,实际上放在哪里并没有关系,只需要在php.ini中写上相对应的路径即可

4.打开php.ini,将原[openssl]配置下的openssl.cafile的值改为[php的安装目录]\extras\openssl\cacert.pem,并去除前面的分号,这里一定要和上面的路径对应

5.大功告成