Composer常用的命令整理
1、composer查看全局设置:composer config -gl
2、查看已存在的包:composer info [***]
or composer show [***]
3、搜索包:composer search ***
4、安装包:composer require
或者composer install
composer require monolog/monolog 添加指定包
composer require monolog/monolog:1.19 添加指定包和版本
composer require monolog/monolog=1.19
composer require monolog/monolog 1.19
对于 require 和 install 是不相同的,require 会把包的信息添加到 composer.json 文件中并进行 install 。
而 install 是直接从 composer.json 或 composer.lock 文件中提取依赖信息,然后进行安装。
不编辑composer.json的情况下安装库:
你可能会觉得每安装一个库都需要修改composer.json太麻烦,那么你可以直接使用require命令。如:composer require "foo/bar:1.0.0"
5、清理缓存:composer clearcache
6、依赖性检测:composer depends ***
7、设置composer镜像为国内镜像:
composer config -g repo.packagist composer https://packagist.phpcomposer.com
也可以用下面这个:
//全局配置
composer config -g repos.packagist composer https://mirrors.tencent.com/composer/
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
//单独项目配置
composer config repo.packagist composer https://mirrors.aliyun.com/composer/
8、卸载某个扩展或者删除某个包:composer remove
composer remove vendorName/packageName
这只是删除了依赖关系,不会自动加载,但其依赖包还在vender文件夹里,可手动删除
9、诊断:composer diagnose
➜ basic composer diagnose
Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: FAIL
[Composer\Downloader\TransportException] The "https://api.github.com/rate_limit" file could not be downloaded: failed to open stream: Connection refused
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0 87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B 0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 1.10.8
PHP version: 7.2.7
PHP binary path: /Applications/MAMP/bin/php/php7.2.7/bin/php
OpenSSL version: OpenSSL 1.0.2o 27 Mar 2018
以上是执行结果就是检测的结果正常,但有时可能出现一些警告,具体情况具体分析。
设置一个本地或全局的composer配置:
composer config secure-http false
全局设置:
composer config -g secure-http false
composer self-update --rollback
10、Mac上卸载Composer:
where composer 或者type composer或brew info composer
rm -rf /usr/bin/composer
rm -rf /usr/local/bin/composer.phar
11、Composer升级到v2.x:composer self-update --2
12、Composer回退到v1.X:composer self-update --1
慎用composer update!慎用composer update!慎用composer update!
参考:
https://pkg.phpcomposer.com/#how-to-install-composer
https://blog.csdn.net/wulove52/article/details/78392663
PHP 开发者该知道的 5 个 Composer 小技巧:
https://www.phpcomposer.com/5-features-to-know-about-composer-php/
https://segmentfault.com/q/1010000003876622/a-1020000006835543
https://developer.aliyun.com/composer?spm=a2c6h.13651102.0.0.3e221b11ccSpCA
正确的 Composer 扩展包安装方法:
https://www.cnblogs.com/caicaizi/p/9131845.html
修复:https://getcomposer.org/doc/articles/troubleshooting.md#general