Composer常见错误解决-值得收藏

执行composer install遇到错误:Your requirements could not be resolved to an installable set of packages. 这是因为不匹配composer.json要求的版本。

完整错误如下:

vagrant@homestead:/usr/share/nginx/html/laravel-blog$ sudocomposerinstall
Loadingcomposerrepositorieswithpackage information
Installingdependencies (includingrequire-dev) fromlockfile
Yourrequirementscouldnot beresolvedto aninstallablesetofpackages.
 
  Problem 1
    - Installationrequestfor doctrine/instantiator 1.0.3 -> satisfiablebydoctrine/instantiator[1.0.3].
    - doctrine/instantiator 1.0.3 requiresphp ~5.3 -> yourPHPversion (7.0.3) doesnot satisfythatrequirement.
  Problem 2
    - doctrine/instantiator 1.0.3 requiresphp ~5.3 -> yourPHPversion (7.0.3) doesnot satisfythatrequirement.
    - phpunit/phpunit-mock-objects 2.3.0 requiresdoctrine/instantiator ~1.0,>=1.0.1 -> satisfiablebydoctrine/instantiator[1.0.3].
    - Installationrequestfor phpunit/phpunit-mock-objects 2.3.0 -> satisfiablebyphpunit/phpunit-mock-objects[2.3.0].

提示我的PHP 7版本太高,不符合composer.json需要的版本,但是在PHP 7下应该也是可以运行的,composer可以设置忽略版本匹配,命令是:

composerinstall --ignore-platform-reqs

or

composerupdate --ignore-platform-reqs

再次执行composer命令可以正常安装包了。

如果提示警告:

Cannotcreatecachedirectory /home/vagrant/.composer/cache/repo/https---packagist.org/, or directoryis not writable. Proceedingwithoutcache
  Cannotcreatecachedirectory /home/vagrant/.composer/cache/files/, or directoryis not writable. Proceedingwithoutcache


这是在虚拟机中执行composer,提示这个目录没有可写权限,composer无法缓存下载的包,这样就每次都得重新下载,把目录改成可写可读即可。

sudo chmod -R 777 /home/vagrant/.composer/cache/files/


另外,在虚拟机中也设置composer为国内镜像,不然下载速度慢的要死,执行:

composerconfig -g repo.packagistcomposerhttps://packagist.phpcomposer.com

OK,大功告成。


 



 

在重新安装 Composer 过程中,可能会遇到以下常见错误: 1. "Could not open input file: composer.phar" - 这个错误通常是由于在命令中使用了错误的文件路径,或者没有在命令中指定正确的 Composer 文件名。确保你在命令中正确地指定了 Composer 文件的位置和名称。 2. "The following exception is caused by a lack of memory or swap, or not having swap configured" - 这个错误通常是由于你的服务器上没有足够的内存或交换空间来运行 Composer。你可以尝试增加服务器的内存或交换空间,或者在运行 Composer 命令时使用 --prefer-dist 标志来减少内存使用。 3. "Installation failed, reverting ./composer.json to its original content." - 这个错误通常是由于 Composer安装依赖项时遇到了错误。你可以查看 Composer 的输出信息来查找出错的原因,并尝试重新运行安装命令。 4. "Composer detected issues in your platform: Your Composer dependencies require a PHP version " - 这个错误通常是由于你的 PHP 版本不符合 Composer 依赖项的要求。你可以尝试升级 PHP 版本,或者在运行 Composer 命令时使用 --ignore-platform-reqs 标志来忽略版本要求。 5. "The requested PHP extension ext-xxx * is missing from your system." - 这个错误通常是由于你的系统缺少必需的 PHP 扩展,需要手动安装扩展或启用扩展。你可以通过搜索相关的扩展以及安装方法来解决问题。 希望这些信息对你有所帮助!
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值