- 首先
php
已经配置到环境变量 - 打开命令行窗口,进入你想安装
composer
的目录 - 执行命令:
php -r "readfile('https://getcomposer.org/installer');" | php
此过程可能会报错:
Warning: readfile(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify faile
d in Command line code on line 1
Warning: readfile(): Failed to enable crypto in Command line code on line 1
Warning: readfile(https://getcomposer.org/installer): failed to open stream: ope
ration failed in Command line code on line 1
解决办法:
确保 php.ini 已经 开启 openssl 并配置了 CA 证书
openssl.cafile=E:\PHPTools\php\cert\cacert.pem
证书下载地址: https://curl.haxx.se/docs/caextract.html
- 最后执行命令:
echo @php "%~dp0composer.phar" %*>composer.bat
然后将此 composer 目录配置到环境变量,重新打开 cmd 命令窗口,执行 composer -v 如果看到版本信息说明安装成功
此过程需要能访问 getcomposer.com ,该网址被墙了,如果无法访问,可以自行百度下载 composer.phar 文件,然后执行上面的 echo 语句生成可执行文件,就可以了
官方下载地址:http://getcomposer.org/composer.phar