Table of Contents [expand]
Last updated October 23, 2026
You can specify which PHP version to use in your composer.json file. Upon a push, Heroku reads the necessary information from composer.lock, if present, and falls back to composer.json otherwise.
Specifying a Runtime
Specify “php” as a dependency in the require section of your composer.json. For example, here composer.json instructs Heroku to use the latest version of PHP 8 greater or equal to 8.4.0, but not PHP 9:
{
"require": {
"php": "^8.4.0"
}
}
Never specify an exact version like “8.4.27” for PHP, or any other package.
Instead, use the “^” or “~” next significant release operators to ensure that you get appropriate updates upon push as they become available.
For example, specifying “~8.4.0” provides the latest 8.4.x release. This specification is fully compatible with other releases from the 8.4 series, but can contain security or performance updates. It isn’t compatible with PHP 8.5 or later.
To get the latest PHP 8.4 or later (including PHP 8.5 and more) but not PHP 9, specify “^8.4.0”.
Next, make sure that your new requirements are “frozen” to composer.lock by running:
$ composer update
Finally, don’t forget to git add and git commit both files.
On your next push, Heroku prints the versions that are resolved and installs:
-----> Installing platform packages...
- php (8.4.27)
Specifying an unknown or unsupported version results in an error listing potential alternative versions. See Supported Versions and Available Versions for the PHP versions available on each stack.
If you don’t specify a PHP version, Heroku uses the default PHP runtime version.