一、参考链接

阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (aliyun.com)

阿里云 Composer 全量镜像

Composer 中文网 / Packagist 中国全量镜像 (phpcomposer.com)

PHP: Windows 下的 PHP 安装程序工具 - Manual

Composer 安装与使用 | 菜鸟教程 (runoob.com)

Packagist / Composer 中国全量镜像 (pkg.xyz)

二、Composer 全量镜像介绍

三、阿里云 Composer 全量镜像安装操作

1️⃣ Windows系统下安装PHP开发环境

下载链接:PHP For Windows: Binaries and sources Releases

下载最新线程安全版PHP zip压缩包,解压缩后放在想要安装的路径下

2️⃣测试PHP是否安装成功

C:\Users\xybdiy>php -v
PHP 8.1.1 (cli) (built: Dec 15 2021 10:31:43) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies

C:\Users\xybdiy>

3️⃣ 方法一:安装 Composer(取其一即可)

Windows系统下安装Composer-Setup.exe

下载链接:Composer-Setup.exe

4️⃣ 方法二:安装 Composer(两种方法取其一即可)

参考链接Packagist / Composer 中国全量镜像 (pkg.xyz)

Microsoft Windows [版本 10.0.19043.1415]
(c) Microsoft Corporation。保留所有权利。

# 下载安装脚本 - composer-setup.php - 到当前目录。
C:\Users\xybdiy>php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"

# 执行安装过程。
C:\Users\xybdiy>php composer-setup.php
All settings correct for using Composer
Downloading...

Composer (version 2.1.14) successfully installed to: C:\Users\xybdiy\composer.phar
Use it: php composer.phar

# 删除安装脚本。
C:\Users\xybdiy>php -r "unlink('composer-setup.php');"

C:\Users\xybdiy>

# 查看是否正确输出版本号。
C:\Users\xybdiy>composer --version
Composer version 2.1.14 2021-11-30 10:51:43

C:\Users\xybdiy>

5️⃣测试composer

# 查看是否正确输出版本号。
C:\Users\xybdiy>composer --version
Composer version 2.1.14 2021-11-30 10:51:43

C:\Users\xybdiy>
C:\Users\xybdiy>composer selfupdate
You are already using the latest available Composer version 2.1.14 (stable channel).

C:\Users\xybdiy>

6️⃣更改阿里云 Composer 全量镜像

全局配置(推荐)

所有项目都会使用该镜像地址:

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

取消配置:

composer config -g --unset repos.packagist
Microsoft Windows [版本 10.0.19043.1415]
(c) Microsoft Corporation。保留所有权利。

C:\Users\xybdiy>composer --version
Composer version 2.1.14 2021-11-30 10:51:43

C:\Users\xybdiy>composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

C:\Users\xybdiy>composer config -g --unset repos.packagist

C:\Users\xybdiy>

7️⃣ 可能出现的问题

  1. 建议先将Composer版本升级到最新:
C:\Users\xybdiy>composer self-update
You are already using the latest available Composer version 2.1.14 (stable channel).

C:\Users\xybdiy>
  1. 执行诊断命令:
C:\Users\xybdiy>composer diagnose
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.1.14
PHP version: 8.1.1
PHP binary path: C:\Program Files (x86)\php-8.1.1-Win32-vs16-x64\php.exe
OpenSSL version: OpenSSL 1.1.1l  24 Aug 2021
cURL version: 7.77.0 libz 1.2.11 ssl OpenSSL/1.1.1l
zip: extension present, unzip not available, 7-Zip not available

C:\Users\xybdiy>
  1. 清除缓存:
C:\Users\xybdiy>composer clear
Cache directory does not exist (cache-vcs-dir):
Cache directory does not exist (cache-repo-dir):
Cache directory does not exist (cache-files-dir):
Clearing cache (cache-dir): C:\Users\xybdiy\AppData\Local\Composer
All caches cleared.

C:\Users\xybdiy>
  1. 若项目之前已通过其他源安装,则需要更新 composer.lock 文件,执行命令:
C:\Users\xybdiy>composer update --lock
03-05 20:22