Composer配置国内镜像及版本更新 无
2727
2016-09-25
Composer在Windows上的安装还是很简单的,exe一键执行,但在版本更新以及插件下载上由于国内网络的现状,十有八九不是无法访问就是超时失败。我是很早前为了安装Laravel下载的Composer,结果在最近为了给Laravel安装PRedis插件时提示版本太旧,update更新时一直超时,后来发现国内有好心人搭了镜像,速度很快,基本和源站是同步的。
修改方法
Composer的配置文件包括系统全局配置和具体项目配置。
修改项目配置:
直接定位到项目目录,右键User Composer here或者cmd定位到项目目录,然后执行
composer config repo.packagist composer https://packagist.phpcomposer.com
或者也可以直接打开项目目录下的composer.json文件,找到repositories,将这段配置整个替换为
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
修改全局配置
cmd执行命令
composer config -g repo.packagist composer https://packagist.phpcomposer.com
或者找到Composer安装目录下的composer.json文件修改,如果忘记了Composer的安装目录,可以cmd执行
composer config -l -g
表示列出(list)全局(global)配置(config)信息,大致如下
C:WINDOWSsystem32>composer config -l -g
You are running composer with xdebug enabled. This has a major impact on runtime
performance. See https://getcomposer.org/xdebug
[repositories.packagist.type] composer
[repositories.packagist.url] https://packagist.phpcomposer.com
[process-timeout] 300
[use-include-path] false
[preferred-install] auto
[notify-on-install] true
[github-protocols] [https, ssh, git]
[vendor-dir] vendor (C:WINDOWSsystem32/vendor)
[bin-dir] {$vendor-dir}/bin (C:WINDOWSsystem32/vendor/bin)
[cache-dir] C:/Users/Administrator/AppData/Local/Composer
[data-dir] C:/Users/Administrator/AppData/Roaming/Composer
[cache-files-dir] {$cache-dir}/files (C:/Users/Administrator/AppData/Local/Compo
ser/files)
[cache-repo-dir] {$cache-dir}/repo (C:/Users/Administrator/AppData/Local/Compose
r/repo)
[cache-vcs-dir] {$cache-dir}/vcs (C:/Users/Administrator/AppData/Local/Composer/
vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[bin-compat] auto
[discard-changes] false
[autoloader-suffix]
[sort-packages] false
[optimize-autoloader] false
[classmap-authoritative] false
[prepend-autoloader] true
[github-domains] [github.com]
[bitbucket-expose-hostname] true
[disable-tls] false
[secure-http] false
[cafile]
[capath]
[github-expose-hostname] true
[gitlab-domains] [gitlab.com]
[store-auths] prompt
[archive-format] tar
[archive-dir] .
[home] C:/Users/Administrator/AppData/Roaming/Composer
其中最后一行就是Composer的安装位置。
最后执行composer selfupdate更新到最新版本1.2.1
F:wwwelittle-master>composer selfupdate
Your version of PHP, 5.4.17, is affected by CVE-2013-6420 and cannot safely perform certificate validation, we strongly suggest you upgrade.
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
You are already using composer version 1.2.1 (stable channel).
备注
- 如果已经使用了Composer安装时的配置创建了项目,那么如果仅修改全局配置文件,项目中的composer.json优先级是更高的,所以要全部修改。
- 之前国内镜像是只支持http协议,所以还需要修改配置文件中的secure-http为false,现在不需要了,已经支持了https。
- Composer中文在线文档