一、参考链接
阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (aliyun.com)
Composer 中文网 / Packagist 中国全量镜像 (phpcomposer.com)
PHP: Windows 下的 PHP 安装程序工具 - Manual
Composer 安装与使用 | 菜鸟教程 (runoob.com)
Packagist / Composer 中国全量镜像 (pkg.xyz)
二、Composer 全量镜像介绍
Composer 是 PHP 的一个依赖管理工具。它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们。
三、阿里云 Composer 全量镜像安装操作
1️⃣ Windows系统下安装PHP开发环境
下载链接:PHP For Windows: Binaries and sources Releases
下载最新线程安全版PHP zip压缩包,解压缩后放在想要安装的路径下
2️⃣测试PHP是否安装成功
C:\Users\xybdiy>php -vPHP 8.1.1 (cli) (built: Dec 15 2021 10:31:43) (ZTS Visual C++ 2019 x64)Copyright (c) The PHP GroupZend Engine v4.1.1, Copyright (c) Zend TechnologiesC:\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.phpAll settings correct for using ComposerDownloading...Composer (version 2.1.14) successfully installed to: C:\Users\xybdiy\composer.pharUse it: php composer.phar# 删除安装脚本。C:\Users\xybdiy>php -r "unlink('composer-setup.php');"C:\Users\xybdiy># 查看是否正确输出版本号。C:\Users\xybdiy>composer --versionComposer version 2.1.14 2021-11-30 10:51:43C:\Users\xybdiy>
5️⃣测试composer
# 查看是否正确输出版本号。C:\Users\xybdiy>composer --versionComposer version 2.1.14 2021-11-30 10:51:43C:\Users\xybdiy>
提示:不要忘了经常执行 ==composer selfupdate== 以保持 Composer 一直是最新版本哦!
C:\Users\xybdiy>composer selfupdateYou 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 --versionComposer version 2.1.14 2021-11-30 10:51:43C:\Users\xybdiy>composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/C:\Users\xybdiy>composer config -g --unset repos.packagistC:\Users\xybdiy>
7️⃣ 可能出现的问题
建议先将Composer版本升级到最新:
C:\Users\xybdiy>composer self-updateYou are already using the latest available Composer version 2.1.14 (stable channel).C:\Users\xybdiy>
执行诊断命令:
C:\Users\xybdiy>composer diagnoseChecking platform settings: OKChecking git settings: OKChecking http connectivity to packagist: OKChecking https connectivity to packagist: OKChecking github.com rate limit: OKChecking disk free space: OKChecking pubkeys:Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0 87719BA6 8F3BB723 4E5D42D0 84A14642Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B 0C708369 153E328C AD90147D AFE50952OKChecking composer version: OKComposer version: 2.1.14PHP version: 8.1.1PHP binary path: C:\Program Files (x86)\php-8.1.1-Win32-vs16-x64\php.exeOpenSSL version: OpenSSL 1.1.1l 24 Aug 2021cURL version: 7.77.0 libz 1.2.11 ssl OpenSSL/1.1.1lzip: extension present, unzip not available, 7-Zip not availableC:\Users\xybdiy>
清除缓存:
C:\Users\xybdiy>composer clearCache 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\ComposerAll caches cleared.C:\Users\xybdiy>
若项目之前已通过其他源安装,则需要更新 composer.lock 文件,执行命令:
C:\Users\xybdiy>composer update --lock