用法:
有两种方式启用本镜像服务:
- 将以下配置信息添加到 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} ] }