composer切换国内源

1、局部换源(仅对当前项目有效)

在当前项目下的composer.json中添加

{
"repositories": [
        {
            "type": "composer",
            "url": "https://mirrors.aliyun.com/composer/" //第一个源
        },
        {
            "type": "composer",
            "url": "https://mirrors.cloud.tencent.com/composer/" //第二个源
        },
}

寻找包的过程是先从第一个源中寻找,如果找不到就从第二个源中寻找,这里可以配置多个composer资源库

2、全局换源
首先把默认的源给禁用掉
root@6d6d1fafd4be:/var/www# composer config -g secure-http false
再修改镜像源 这里使用是阿里的源
root@6d6d1fafd4be:/var/www# composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
修改成功后可以先查看一下配置
root@6d6d1fafd4be:/var/www# composer config -g -l
[repositories.packagist.org.type] composer
[repositories.packagist.org.url] https://mirrors.aliyun.com/composer/
[process-timeout] 300
[use-include-path] false
[use-parent-dir] prompt
[preferred-install] dist
[notify-on-install] true
[github-protocols] [https, ssh, git]
[gitlab-protocol] 
[vendor-dir] vendor (/var/www/vendor)
[bin-dir] {$vendor-dir}/bin (/var/www/vendor/bin)
[cache-dir] /root/.composer/cache
[data-dir] /root/.composer
[cache-files-dir] {$cache-dir}/files (/root/.composer/cache/files)
[cache-repo-dir] {$cache-dir}/repo (/root/.composer/cache/repo)
[cache-vcs-dir] {$cache-dir}/vcs (/root/.composer/cache/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[cache-read-only] false
[bin-compat] auto
[discard-changes] false
[autoloader-suffix] 
[sort-packages] false
[optimize-autoloader] false
[classmap-authoritative] false
[apcu-autoloader] 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] .
[htaccess-protect] true
[use-github-api] true
[lock] true
[platform-check] php-only
[home] /root/.composer

第二行repositories.packagist.org.url 如果是阿里的就代表成功

注意:如果修改了全局的话 就不用再去项目下修改composer.json配置文件了 如果当前项目的composer.json已经配置过,那会是当前项目下指定的源

你可能感兴趣的:(composer切换国内源)