下面由composer使用教學欄位來跟大家介紹Composer設定忽略版本匹配的方法,希望對需要的朋友有幫助!
Composer簡介
#Composer 是 PHP 的一個依賴管理工具。它允許你申明專案所依賴的程式碼庫,它會在你的專案中為你安裝他們。 Composer 不是套件管理器。是的,它涉及 "packages" 和 "libraries",但它在每個專案的基礎上進行管理,在你專案的某個目錄中(例如 vendor)進行安裝。預設情況下它不會在全域安裝任何東西。因此,這只是一個依賴管理。
執行composer install遇到錯誤:Your requirements could not be resolved to an installable set of packages. 這是因為不符合composer.json要求的版本。
完整錯誤如下:
vagrant@homestead:/usr/share/nginx/html/laravel-blog$ sudo composer install Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for doctrine/instantiator 1.0.3 -> satisfiable by doctrine/instantiator[1.0.3]. - doctrine/instantiator 1.0.3 requires php ~5.3 -> your PHP version (7.0.3) does not satisfy that requirement. Problem 2 - doctrine/instantiator 1.0.3 requires php ~5.3 -> your PHP version (7.0.3) does not satisfy that requirement. - phpunit/phpunit-mock-objects 2.3.0 requires doctrine/instantiator ~1.0,>=1.0.1 -> satisfiable by doctrine/instantiator[1.0.3]. - Installation request for phpunit/phpunit-mock-objects 2.3.0 -> satisfiable by phpunit/phpunit-mock-objects[2.3.0].
提示我的PHP 7版本太高,不符合composer.json需要的版本,但是在PHP 7下應該也是可以運行的,composer可以設定忽略版本匹配,指令是:
composer install --ignore-platform-reqs or composer update --ignore-platform-reqs
再次執行composer指令可以正常安裝套件了。
如果提示警告:
Cannot create cache directory /home/vagrant/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache Cannot create cache directory /home/vagrant/.composer/cache/files/, or directory is not writable. Proceeding without cache
這是在虛擬機器中執行composer,提示這個目錄沒有可寫權限,composer無法快取下載的包,這樣就每次都得重新下載,把目錄改成可寫可讀即可。
sudo chmod -R 777 /home/vagrant/.composer/cache/files/
另外,在虛擬機器中也設定composer為國內鏡像,不然下載速度慢的要死,執行:
composer config -g repo.packagist composer https://packagist.phpcomposer.com
OK,大功告成。
以上是Composer如何設定忽略版本匹配的詳細內容。更多資訊請關注PHP中文網其他相關文章!