1、composer查看全局设置:composer config -gl
2、查看已存在的包:composer info
3、搜索包:composer search ***
4、安装包:composer require
或者composer install
对于 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镜像为国内镜像:
设置composer镜像为国内镜像:
composer config -g repo.packagist composer https://packagist.phpcomposer.com
上面地址前几天崩了,可以用下面这个:
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ //全局配置
composer config repo.packagist composer https://mirrors.aliyun.com/composer/ //单独项目配置
7、Composer 卸载某个扩展或者删除某个包
composer remove vendorName/packageName
这只是删除了依赖关系,不会自动加载,但其依赖包还在vender文件夹里,可手动删除
8、Mac上卸载Composer:
rm -rf /usr/bin/composer
rm -rf /usr/local/bin/composer.phar
9、实例
➜ 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
[ComposerDownloaderTransportException] 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
以上是执行结果就是检测的结果 那个警告比较清楚的说明是通过 http 不安全协议
解决方法是设置一个本地或全局的composer配置:
composer config secure-http false
全局设置:
composer config -g secure-http false</packages>
慎用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