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
).
Leave a Reply