我是tp5.1下,用composer安装扩展包,在命令行运行,无任何不反应,不下载也不报错,这时,我们先ctrl+c退出执行的命令,然后在tp5.1根目录下,找到composer.json文件,并用编辑器打开,在最后追加上如下内容:
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
保存退出,然后在cmd命令行执行运行命令,就ok了。
composer安装扩展包时,可以设置忽略版本匹配,命令如下:
composer install --ignore-platform-reqs
如果不知道扩展包的具体版本,可以写 * ,* 会下载最新的版本
"require": {
"topthink/think-helper":"*"
},
或者写 dev-master,dev-master作者也是很懵逼
"require": {
"topthink/think-helper":"dev-master"
},
再或者随便填写一个不存在的版本,cmd命令执行的时候,会报错,这时会提示该扩展包有哪些版本号,如作者填写的是 1.0 版本,当然这个版本执行的时候会报错并列出改扩展包都有哪些版本
"require": {
"topthink/think-helper":"1.0"
},
然后填写到composer.json文件里,然后在命令行进行执行 composer update,就会进行安装,ok了。
安装报错
错误如下:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- overtrue/http 1.0.1 requires php >=7.0 -> your PHP version (5.6.34) does not satisfy that requirement.
- overtrue/http 1.0.0 requires php >=7.0 -> your PHP version (5.6.34) does not satisfy that requirement.
- overtrue/sendcloud 1.0.0 requires overtrue/http dev-master -> satisfiable by overtrue/http[dev-master] but these conflict with your requirements or minimum-stability.
- overtrue/sendcloud 1.0.1 requires overtrue/http ^1.0 -> satisfiable by overtrue/http[1.0.0, 1.0.1].
- Installation request for overtrue/sendcloud ^1.0 -> satisfiable by overtrue/sendcloud[1.0.0, 1.0.1].
Installation failed, reverting ./composer.json to its original content.
这是因为php版本不匹配,如下执行命令,进行忽略版本
composer install --ignore-platform-reqs
或者
composer update --ignore-platform-reqs
再次执行composer命令可以正常安装包了。