W3docs

Tell Composer to use Different PHP Version

To use a specific version of PHP with Composer, you can specify the version you want to use in the config section of your composer.json file.

To use a specific version of PHP with Composer, you can specify the version you want to use in the config section of your composer.json file. For example:

How to make Composer use a different PHP version?

{
    "name": "example/project",
    "require": {},
    "config": {
        "platform": {
            "php": "7.4"
        }
    }
}

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

Alternatively, you can specify the PHP version you want to use on the command line when you run Composer. For example:

composer config platform.php 7.4