178

We are using PHPCI and composer. The server which runs PHPCI is on PHP 5.3.

For a project we added the Facebook PHP SDK, using composer. It requires PHP 5.4. Composer gets triggered by PHPCI and get executed. But because the CI server just got PHP 5.3 composer failed with the error message:

facebook/php-sdk-v4 4.0.9 requires php >=5.4.0 -> no matching package found.

This let fail my build in PHPCI, of course.

Is there a possibility to skip this requirement? Maybe by adding an option to composer.json? Or a parameter to composer.phar call?

dreftymac
  • 31,404
  • 26
  • 119
  • 182
Armin
  • 15,582
  • 10
  • 47
  • 64

3 Answers3

434

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

hakre
  • 193,403
  • 52
  • 435
  • 836
Armin
  • 15,582
  • 10
  • 47
  • 64
29

For many commands, you can tell composer to bypass php version check, with parameter "--ignore-platform-reqs":

composer COMMAND --ignore-platform-reqs

this will bypass php version specification.

Be aware that the software may work or not: php version specification is there because somewhere in the code is needed at least the specified php version, so if you use that code the software will break.

Luca C.
  • 11,714
  • 1
  • 86
  • 77
-15

If anything requires a specific version of PHP, it won't run in a lower version of PHP. You will properbly still recieve errors when bypassing the PHP requirement.

Btw, PHP 5.3 is no longer maintained, I would strongly recommend updating the PHPCI server.

Wouter J
  • 41,455
  • 15
  • 107
  • 112
  • 6
    First I would like to know how to bypass the PHP requirement. – Armin Oct 06 '14 at 09:02
  • 1
    You can't and you won't as the code won't work in a lower php version – Wouter J Oct 06 '14 at 09:06
  • 5
    It will. Just the CI server got the low PHP version. The server which contains the facebook SDK runs on PHP 5.4. It is just about the ci server, which packs everything to a nice deployable zip file. – Armin Oct 06 '14 at 13:34
  • 1
    Although PHP 5.3 is no longer maintained by the core PHP developers, some flavours of Linux still support it and will do for a while yet. Ubuntu 12.04 LTS ships with 5.3 and is supported until April 2017 (https://wiki.ubuntu.com/LTS). Moving to 14.04 is the best upgrade path but there are breaking changes which require an amount of work to fix (Apache 2.4, php-fpm etc). Hence a lot of the internet still using 5.3.x. – Andrew McCombe Mar 30 '15 at 10:13
  • 4
    true unfortunately 99% of packages even the well supported ones don't have the proper requirements. It's more a indicator of what the developer is using than anything else. – michael.schuett Feb 15 '17 at 04:08
  • "it won't run in a lower version of PHP". The statement is simply no true. The package that OP is trying to install might run just fine. Perhaps this should have been a comment. – istepaniuk Jan 31 '21 at 20:15