How to Always Use Ignore-Platform-Reqs Flag When Running Composer

How to always use ignore-platform-reqs flag when running composer?

It's recommended to fake php version, rather than ignore platform requirements. Add

"platform":{"php":"5.5"}

to your ~/.composer/config.json or use composer config -g -e to edit it.

An example of sufficient config to fake php version:

{
"config": {
"platform":{
"php":"5.5"
}
}
}

It may have much more options though.

UPDATE:
starting from v2.3.0 you can use environment variables.
Please see Yakatz' answer

How can I resolve Your requirements could not be resolved to an installable set of packages error?

Your software dependencies have an incompatible version conflict.

At the same time you want to install any Laravel 4.2.x version, and "zizaco/entrust" from its master branch. And that master branch requires at least Laravel 5.0 (roughly speaking).

The problem comes from the dependency on branches. It's likely that the package zizaco/entrust once was using Laravel 4.2 in its master branch, and that you were able to install your dependencies at that day. But the very moment this branch gets updated with an incompatible version requirement, you will never ever be able to run composer update and get updated dependencies.

Always use tagged versions! Ideally you use a relaxed version requirement that allows for compatible updates. This should be expressed as a tilde-two-number version requirement: ~1.2 would install a version 1.2.0 and up (like 1.2.99 or 1.2.100), and also 1.3 and up. If you need a certain patch release: Caret-three-number version ^1.2.10 will install 1.2.10 or up, also 1.3 and up.

Using this version requirement instead of dev-master will allow you to use released versions instead of the unstable state in the master branch, and allows you to address the most recent version that still works with Laravel 4.2. I guess that would be zizaco/entrust version 1.3.0, but version 1.2 would also qualify. Go with "zizaco/entrust": "~1.2".

Composer installing incompatible package

The solution for me was to remove --ignore-platform-reqs. For any forward-leaning packages (any Ocramius package, for instance), this will either fail hard like this did, or you'll have several strange bugs you can't seem to track down the cause of.

What --ignore-platform-reqs does is it switches off the checks Composer makes to ensure that only packages compatible with the environment works. In this case, the offending package had a recent update to use PHP 7.4, and happened to use the new property type declarations in the Composer installer.

I had been battling several other weirdnesses (like the Doctrine's Entity Manager failing randomly, another Ocramius-related package), which all went away by removing the flag when I ran Composer. Whatever the reason I needed it years ago, I no longer do.

If you feel you need it, check out config.platform which seems to allow you to lie to Composer, or work to remove needing that flag altogether (why-ever you think you need it, get over it if possible).

Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: {"php": "7.0.3", "ext-something": "4.0.3"}.

https://getcomposer.org/doc/06-config.md#platform

Override PHP base dependency in composer

The error message indicates a requirement from the main composer.json. The version requirement can be just adapted:

"require": {
"php": ">=5.5",

After changing the version like this I get:

  Problem 1
- Installation request for classpreloader/classpreloader 2.0.0 -> satisfiable by classpreloader/classpreloader[2.0.0].
- classpreloader/classpreloader 2.0.0 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
Problem 2
- Installation request for laravel/framework v5.1.17 -> satisfiable by laravel/framework[v5.1.17].
- laravel/framework v5.1.17 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
Problem 3
- Installation request for laravelcollective/html v5.1.6 -> satisfiable by laravelcollective/html[v5.1.6].
- laravelcollective/html v5.1.6 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
Problem 4
- laravel/framework v5.1.17 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
- jenssegers/agent v2.1.7 requires illuminate/support ~4.0|~5.0 -> satisfiable by laravel/framework[v5.1.17].
- Installation request for jenssegers/agent v2.1.7 -> satisfiable by jenssegers/agent[v2.1.7].

Using the following snippet in composer.json, a php version can be simulated

[...]
"config": {
"preferred-install": "dist",
"platform": {
"php": "5.5.9"
}
}

Doc: https://getcomposer.org/doc/06-config.md#platform

platform

Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: {"php": "5.4", "ext-something": "4.0"}.

Don't forget to run a composer.phar update after this

Satisfy Composer platform dependency using alternative path

You can run composer through your php54 executable. Either call it explicitly php54 composer.phar ... but that is painful if you have composer installed globally. In that case you're probably better off doing a shell script called composer that will call the phar file with php54 or register a bash alias for it.



Related Topics



Leave a reply



Submit