Skip composer PHP requirement
I've found the option:
composer install --ignore-platform-reqs
Ignore platform requirements (php & ext- packages).
Alternative: Specify your projects' PHP version
You can skip the platform checks by configuring composer.json#/config/platform/php
with the PHP version to use.
Composer will fetch packages based on that configured PHP version then.
So when you need to tell Composer the PHP version for your projects dependencies, you can (and should) specify the PHP version if different than the PHP version you execute composer
with in your composer.json
project configuration file (AKA root package):
{
"config": {
"platform": {
"php": "5.6.6"
}
}
}
Here PHP 5.6.6 version is exemplary, it could be 8.0.4
or any other PHP version.
This also documents the target (platform) PHP configuration. Additionally installed PHP extensions and library versions can be specified.
Compare: Config: platform - Composer documentation
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.
composer install -n --ignore-platform-reqs not ignoring PHP extension
Instead of using --ignore-platform-reqs
or provide
hack it is better to mimic your environment using platform
setting - it gives you more control about platform requirements and it is more intuitive than provide
(your package does not really provide ext-fileinfo
):
"config": {
"platform": {
"php": "7.2.14",
"ext-fileinfo": "1.0.5",
"ext-pdo": "7.2.14",
"ext-session": "7.2.14",
"ext-iconv": "7.2.14",
"ext-zip": "1.15.4"
}
},
Actual versions of extensions you may find by calling this command on production environment (although you could probably put anything for extensions version - it is quite uncommon to use anything except *
as a constraint for PHP extensions):
composer show -p
Reference - Composer error Your PHP version does not satisfy requirements after upgrading PHP
The Problem
As well as the versions of other packages they require, Composer packages can specify the versions of PHP which they support.
While resolving the versions of packages to install, Composer has to find versions which match all the constraints in place:
- The version constraints you've specified for dependencies in your
composer.json
- The version constraints each package has specified for its dependencies
- The PHP versions each package supports
If there is no package that satisfies all of those constraints, you will get an error.
Common Confusions
Note that the version constraint for PHP version follows the same rules as other composer constraints. So a constraint of ^7.0
means "any version of 7.x above 7.0", and does not include 8.0.
The Solution
To solve the problem, you need to relax one of those constraints:
- Look at the package mentioned in the error message (
acme/some-package
in the example) and find it on Packagist (or whatever custom package source you have configured). - See if a newer version exists that supports your PHP version.
- If it doesn't, you'll need to find out what's needed to add that support. This might mean checking out the project directly, running its tests, and submitting a patch to mark it as compatible with the new version.
- If (when) support has been added, you'll need to make sure your
composer.json
, and other packages you depend on, don't exclude that new version. For instance, if you currently depend onacme/some-package
version^1.0
, but PHP 8.0 is only supported from version 2.2.0 onwards, you'll need to change your constraint to^2.2
, and make sure your application is still compatible.
Temporary Workaround
Sometimes, you're pretty sure your application will run fine with the same versions of packages as you were previously using. In that case, you can use the platform
configuration variable in your composer.json
to pretend you're still using the old version. This should only be done as a temporary workaround or for testing as it means packages will be installed which may be completely broken on your new PHP version.
For example:
{
"config": {
"platform": {
"php": "7.4.999"
}
}
}
See also "Override PHP base dependency in composer"
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
Can I specify php memory limit requirements in composer json? Perhaps in the config.platform node?
UPDATE: Although this is the only working solution provided - please read the comment thread. There are good arguments against this. Also, this requires strong working knowledge of writing and deploying vendor packages. Specifically, you'll want to know how to roll this back when a better solution is posted or the problematic package is fixed.
Add a little php file to your composer project or package.
composer.json
{
...
"autoload": {
...
"files": ["tweak_ini.php"]
}
}
tweak_ini.php
Obviously you'll want to add some logic to make sure you aren't downgrading.
ini_set('memory_limit','1000M');
...
Related Topics
PHP Timezone Database Is Corrupt Error
How to Read a .Txt File with PHP
How to Set Short Tag(<) in PHP
Pdo and MySQL Fulltext Searches
Getting the Text Portion of a Node Using PHP Simple Xml
Need Response Body of Http 500 with File_Get_Contents (Php)
Mysqli Prepare Statement - Returning False, But Why
Do I Need to Escape Backslashes in PHP
Download of .Zip File Runs a Corrupted File PHP
Why Do I Get "Resource Id #4" When I Apply Print_R() to an Array in PHP
Programmatically Determine Whether to Describe an Object with "A" or "An"
Why Preg_Replace Throws Me a "Unknown Modifier" Error