第一安装php 并设置环境变量 php下载地址:https://pan.shyngo.cn/list/%E6%97%A5%E5%B8%B8%E5%B7%A5%E5%85%B7%E8%BD%AF%E4%BB%B6/php_sdk 如果已安装php 且 命令行 `php -v` 输入对应的版本如下可进行第二步 ``` C:\Users\shyn>php -v PHP 7.4.33 (cli) (built: Nov 2 2022 15:06:48) ( NTS Visual C++ 2017 x64 ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies ``` 第二步 `win+R` 打开命令行 ,输入如下`php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"`,下载 `comoser-setup.php` ``` D:\soft\env\php> php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" ``` 第三步 `win+R` 打开命令行输入 `php .\composer-setup.php` 下载 `composer.phar` ``` D:\soft\env\php> php .\composer-setup.php All settings correct for using Composer Downloading... Composer (version 2.6.5) successfully installed to: D:\soft\env\php\composer.phar Use it: php composer.phar ``` 第四步 将下载的 `composer.phar` 拷贝到 `php.exe` 的同级目录 并新建 `composer.bat` 文件 composer.bat 文件内容如下: ``` @php "%~dp0composer.phar" %* ``` 第五步 win+R 命令行输入 `composer --version` 如下效果完成composer 的安装 ``` C:\Users\shyn>composer --version Composer version 2.6.5 2023-10-06 10:11:52 ``` 1. 查看镜像源 系统全局配置: 可以使用 composer config -l -g 查看所有全局配置 单个项目配置: 在当前项目根目录可以使用 composer config -l 查看当前项目镜像配置 2. 修改阿里淘宝镜像源 (1). 配置只在当前项目生效 composer config repo.packagist composer https://mirrors.aliyun.com/composer/ 取消当前项目配置 composer config --unset repos.packagist (2)配置全局生效 composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ 取消全局配置 composer config -g --unset repos.packagist 3. composer 的各类镜像源 ``` composer https://packagist.org phpcomposer https://packagist.phpcomposer.com aliyun https://mirrors.aliyun.com/composer tencent https://mirrors.cloud.tencent.com/composer huawei https://mirrors.huaweicloud.com/repository/php laravel-china https://packagist.laravel-china.org cnpkg https://php.cnpkg.org ```