If you have a (legacy) PHP project running on a legacy server (running PHP 5.4.27 for example), but are locally developing with a more modern PHP version (PHP 7.4 for example), you might end up installing dependencies that are not compatible with the PHP version on the server.
To bypass this, you can tell Composer, via its config
property, which PHP version that you’re using (on production).
{
// …
"config": {
"platform": {
"php": "5.4.27"
}
}
}
When you now run composer require package
, it will only install dependencies that are compatible with that PHP version (instead of the PHP version that’s executing Composer)
💁♂️ You might also want to run that legacy application locally in a Docker container with said PHP version. The Docker West PHP Docker Images will come in handy, although versions prior to PHP 5.6 are supported.
🔐 Even better, of course, is to phase out the production server running that outdated/unsupported/insecure PHP version …
Thank me with a coffee.
I don\'t do this for profit but a small one-time donation would surely put a smile on my face. Thanks!
To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.