Composer ignore-platform-reqs: When You Need That Flag?

Sometimes when using composer install or composer update commands you might install packages that don't fulfill system requirements, something like "your php version (8.1.2) does not satisfy that requirement". To ignore these requirements you can use the flag --ignore-platform-reqs. This flag, for example, can be used to install some package if your system doesn't have some required extension or a different PHP version.

For example, if you would try to install an older Laravel project with a PHP version different than on your system, you would get an error:

Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.
 
Problem 1
- phpspec/prophecy is locked to version 1.12.2 and an update of this package was not requested.
- phpspec/prophecy 1.12.2 requires php ^7.2 || ~8.0, <8.1 -> your php version (8.1.2) does not satisfy that requirement.
Problem 2
- phpspec/prophecy 1.12.2 requires php ^7.2 || ~8.0, <8.1 -> your php version (8.1.2) does not satisfy that requirement.
- phpunit/phpunit 9.5.0 requires phpspec/prophecy ^1.12.1 -> satisfiable by phpspec/prophecy[1.12.2].
- phpunit/phpunit is locked to version 9.5.0 and an update of this package was not requested.

In this case, on my system PHP version is 8.1, but the project requires a version between 7.2 and 8.0.

{
// ...
"require": {
"php": "^7.3|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5"
},
// ...
}

In this case, using composer install --ignore-platform-req=php, would ignore the PHP version check and will install every package.

But, be very careful when ignoring all requirements. Since composer version 2, you can select which requirements to ignore.

composer install --ignore-platform-req=ext-zip

The only difference in these two flags is s at the end of reqs.

You can specify more than one requirement to ignore. For example, ignoring PHP version, and the ext-zip, the command would look like this:

composer install --ignore-platform-req=php --ignore-platform-req=ext-zip

If for some reason, in your project, you will always gonna need to ignore some requirements, you can add a command to composer.json like this:

{
// ...
"scripts": {
// ...
"safe-update-dev": [
"composer update --ignore-platform-req=php --ignore-platform-req=ext-zip"
],
"safe-install-dev": [
"composer instal --ignore-platform-req=php --ignore-platform-req=ext-zip"
],
},
// ...
}

Now, instead of composer install and composer update you would run safe-install-dev and safe-update-dev respectively.

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 68 courses (1183 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses