The following tutorial column using by composer will introduce to you how to set up Composer to ignore version matching. I hope it will be helpful to friends in need!
Introduction to Composer
Composer is a dependency management tool for PHP. It allows you to declare code libraries that your project depends on and it will install them for you in your project. Composer is not a package manager. Yes, it involves "packages" and "libraries", but it's managed on a per-project basis, with installations in some directory within your project (e.g. vendor). By default it won't install anything globally. So this is just a dependency management.
Executing composer install encountered an error: Your requirements could not be resolved to an installable set of packages. This is because the version required by composer.json does not match.
The complete error is as follows:
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].
It prompts that my PHP 7 version is too high and does not meet the version required by composer.json, but it should be able to run under PHP 7 Yes, composer can be set to ignore version matching. The command is:
composer install --ignore-platform-reqs or composer update --ignore-platform-reqs
Execute the composer command again to install the package normally.
If a warning is prompted:
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
This is when composer is executed in a virtual machine, prompting that this directory does not have writable permissions. Composer cannot cache the downloaded package, so it must be downloaded again every time. Just change the directory to be writable and readable.
sudo chmod -R 777 /home/vagrant/.composer/cache/files/
In addition, set composer as the domestic image in the virtual machine, otherwise the download speed will be extremely slow. Execute:
composer config -g repo.packagist composer https://packagist.phpcomposer.com
OK, and you're done.
The above is the detailed content of How to set Composer to ignore version matching. For more information, please follow other related articles on the PHP Chinese website!