Composer常見錯誤解決-值得收藏

執行composer install遇到錯誤:Your requirements could not be resolved to an installable set of packages. 這是因爲不匹配composer.json要求的版本。

完整錯誤如下:

 


 
  1. vagrant@homestead:/usr/share/nginx/html/laravel-blog$ sudocomposerinstall

  2. Loadingcomposerrepositorieswithpackage information

  3. Installingdependencies (includingrequire-dev) fromlockfile

  4. Yourrequirementscouldnot beresolvedto aninstallablesetofpackages.

  5.  
  6. Problem 1

  7. - Installationrequestfor doctrine/instantiator 1.0.3 -> satisfiablebydoctrine/instantiator[1.0.3].

  8. - doctrine/instantiator 1.0.3 requiresphp ~5.3 -> yourPHPversion (7.0.3) doesnot satisfythatrequirement.

  9. Problem 2

  10. - doctrine/instantiator 1.0.3 requiresphp ~5.3 -> yourPHPversion (7.0.3) doesnot satisfythatrequirement.

  11. - phpunit/phpunit-mock-objects 2.3.0 requiresdoctrine/instantiator ~1.0,>=1.0.1 -> satisfiablebydoctrine/instantiator[1.0.3].

  12. - 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命令可以正常安裝包了。

如果提示警告:

 


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

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章