1. 全局配置
composer config -g repo.packagist composer https://packagist.phpcomposer.com
2. 仅在项目中使用
#需在项目的composer.json目录执行
composer config repo.packagist composer https://packagist.phpcomposer.com
取消镜像
composer config -g --unset repos.packagist
使用国内镜像安装laravel 示例
composer create-project -vv --prefer-dist laravel/laravel myapp
如果指定国内镜像,下载会很慢,如下面的情况,一直卡住
Installing laravel/laravel (v7.0.0)
- Installing laravel/laravel (v7.0.0): Loading from cache
Extracting archiveCreated project in myapp
> post-root-package-install: @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
这时候可以Ctrl + c
暂时终止安装,然后,为项目手动设置镜像
cd myapp
composer config repo.packagist composer https://packagist.phpcomposer.com
最后,重新安装,会快很多
composer install
php artisan key:generate
php artisan serve
网友评论