國內鏡像http://packagist.phpcomposer.com不能進行訪問

最近使用composer進行php依賴管理,但是國內鏡像http://packagist.phpcomposer.com不能進行訪問,國外鏡像訪問速度也很慢

如圖,系統提示我們

your configuration does not allow to connection to `http://xxxxxxx`,see the https://getcomposer.org/doc/
06-config.md#secure-http for details.

我們可以點擊鏈接https://getcomposer.org/doc/06-config.md#secure-http 看看;也就是如下內容
Defaults to true. If set to true only HTTPS URLs are allowed to be downloaded via Composer. If you really 
absolutely need HTTP access to something then you can disable it, but using Let's Encrypt to get a free SSL
certificate is generally a better alternative.
大概意思也就是說 默認是必須使用https的,而你使用的鏡像是http的。所以我們要修改一下我們的composer.json配置文件;

打開命令行窗口(windows用戶)或控制檯(Linux、Mac 用戶),進入你的項目的根目錄(也就是 composer.json 文件所在目錄),執行如下命令:

composer config repo.packagist composer https://packagist.phpcomposer.com

上述命令將會在當前項目中的 composer.json 文件的末尾自動添加鏡像的配置信息(你也可以自己手工添加):
"repositories": {
    "packagist": {
        "type": "composer",
        "url": "https://packagist.phpcomposer.com"
    }
}

OK,一切搞定!試一下 composer install 來體驗飛一般的速度吧!

參考鏈接:

https://segmentfault.com/q/1010000004517793

http://pkg.phpcomposer.com/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章