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,大功告成。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Getting Started Use the Current Stable Version (7.1) Buil...
    Leonzai阅读 5,952评论 0 3
  • Awesome PHP 一个PHP资源列表,内容包括:库、框架、模板、安全、代码分析、日志、第三方库、配置工具、W...
    guanguans阅读 11,173评论 0 47
  • Composer Repositories Composer源 Firegento - Magento模块Comp...
    零一间阅读 9,343评论 1 66
  • 是什么 如果你知道yum、apt-get、npm、bower等命令中的一种或者多种,那么,你也能很快知道compo...
    旱魃一样阅读 8,356评论 0 9
  • ziadoz在 Github发起维护的一个PHP资源列表,内容包括:库、框架、模板、安全、代码分析、日志、第三方库...
    Gundy_阅读 11,476评论 4 192