composer啟用國內鏡像網站的配置更改辦法
阿新 • • 發佈:2017-11-25
設置 4.2 ins 查詢 esc 全局配置 art linux 用戶 block
用法:
有兩種方式啟用本鏡像服務:
- 將以下配置信息添加到 Composer 的配置文件 config.json 中(系統全局配置)。見“例1”
- 將以下配置信息添加到你的項目的 composer.json 文件中(針對單個項目配置)。見“例2”
為了避免安裝包的時候都要執行兩次查詢,切記要添加禁用 packagist 的設置,如下:
{ "repositories": [ {"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false} ] }
例1,修改 composer 的配置文件
查看 composer 主目錄:通過 composer config -l -g
命令可以列出 composer 的全局配置信息,在這些信息中查找 [home]
配置項就是 composer 的主目錄。Linux 用戶請執行 sudo composer config -l -g
命令。
進入 composer 的主目錄,打開 config.json 文件(如果沒有就自己創建一個),然後增加本鏡像服務的配置信息,最終內容如下:
{ "config": { }, "repositories": [ {"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false} ] }
例2,以 laravel 項目的 composer.json 配置文件為例,添加本鏡像服務配置信息後如下所示(註意最後幾行):
{ "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "laravel/framework": "4.2.*" }, "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php" ] }, "scripts": { "post-install-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-update-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-create-project-cmd": [ "php artisan key:generate" ] }, "config": { "preferred-install": "dist" }, "minimum-stability": "stable", "repositories": [ {"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false} ] }
註明:個人感覺請使用下面的配置鏡像網站速度會更
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
composer啟用國內鏡像網站的配置更改辦法