• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Draft / Composer fail required PHP version

Composer fail required PHP version

Last updated on November 22, 2019 by Sal Ferrarello

Sometimes your local development version does not have the same PHP version of as your production server or perhaps you’re running composer outside your virtual machine (and your virtual machine has the correct PHP version but your host machine does not).

Since we want to build our dependencies based on the PHP version of our production server, we want composer to pretend we’re using the same PHP version as the production server.

We can do this by adding the following to our composer.json file.

"config": {
    "platform": {
        "php": "7.1.4"
    }
}

Now when composer update runs, it will install the dependencies as if you were running PHP 7.1.4.

Shortcut to Modify composer.json

A quick way to add the above section to your composer.json file is to run the following from the command-line:

composer config platform.php 7.1.4

Update Notice

Previously, this post talked about using

composer update --ignore-platform-reqs

to install your dependencies however this solution is much more likely to cause problems, since you may get some packages that require a higher PHP version (e.g. 7.2 or 7.3).

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Solution Tagged With: composer

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in