我们使用 composer 的时候现在包经常很慢很卡这个时候怎么办呢我们只需要修改一下 composer国内镜像源 加速就可以了.
目前所有 composer 源有一下这些
提供商 | 源站地址 | 备注 |
---|---|---|
composer | https://packagist.org | composer官方源站 |
phpcomposer | https://packagist.phpcomposer.com | composer中文网源站(推荐使用) |
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 | laravel源站 |
cnpkg | https://php.cnpkg.org | cnpkg源站 |
sjtug | https://packagist.mirrors.sjtug.sjtu.edu.cn | sjtug源站 |
全局配置 composer国内镜像源 加速
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
unset取消配置全局 composer国内镜像源 加速
composer config -g --unset repos.packagist
配置当前项目 composer国内镜像源
composer config repo.packagist composer https://mirrors.aliyun.com/composer/
unset取消配置当前项目 composer国内镜像源
composer config --unset repos.packagist
通过修改项目 composer.json 文件配置 composer国内镜像源
{
"name": "xxx/xxx",
"description": "xxxxx",
"authors": [
{
"name": "lmcc",
"email": "001@laiwi.com"
}
],
"repositories": [
{
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
}
]
}
我们也可以同时配置多个国内镜像源以保证 composer 高可用
{
"name": "xxx/xxx",
"description": "xxxxx",
"authors": [
{
"name": "lmcc",
"email": "001@laiwi.com"
}
],
"repositories": [
{
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
},
{
"type": "composer",
"url": "https://mirrors.cloud.tencent.com/composer/"
}
]
}
通过第三方工具修改
我们也可以通过第三方工具 CRM 进行调整配置
composer 调试模式
我们只需要在 composer 命令增加 -vvv 可输出详细的信息
composer require xzz-mifan/phpanalysis -vvv
诊断 composer 命令
composer diagnose
清理 composer 缓存
更换国内源后我们可以执行下清理 composer 缓存
composer clear
更新 composer.lock 文件
如果我们项目之前已通过其他源安装的那么需要更新 composer.lock 文件
composer update --lock
关于怎么修改加速composer国内镜像源的所有解决方法已经介绍完毕了,我们又可以愉快的 composer require xxx 了
评论已关闭