26 October 2017

Composer’s PHP Platform Config

Developers are often bitten when their development environment doesn’t match their production environment close enough. When using composer to manage PHP dependencies, composer might install a version of a package that is fine for your development environment, but wouldn’t meet the requirements in production. While matching the production environment in dev is best, composer does offer a config to help.

"config": {
  "platform": {
    "php": "7.0.19"
  }
},

In this composer.json file, we are telling composer to ignore whatever PHP version composer is running under, and instead pretend composer is running PHP version 7.0.19. Locally, you might be running PHP 5.6.17, but composer will ignore that. Here is an example where the user would have found this handy.

It is possible you could end up with code or packages that don’t work under 5.6.17, but better to discover the incompatibility in development rather than on deploy.