George Gwaro
George Gwaro

Reputation: 69

how do you change the php version that your app uses in heroku platform?

I am trying to change the PHP version that my heroku application uses from the default 7.1 to 7.0. When I try to define it in composer.json it is ignored. What do I need to do?

Upvotes: 6

Views: 6613

Answers (4)

kernel
kernel

Reputation: 55

Yo dont need to downgrade the heroku stack to 18 or anything, You can just change the required version of PHP in composer.json then run composer update against your project and finally deploy /build it to the cloud

Upvotes: 0

sahil srivastava
sahil srivastava

Reputation: 158

Apart from updating composer file, if your application requires "php": ^5.6.0" or 7.0.32 you need to make sure that, heroku stack that you are using is 'heroku-16' and not 'heroku-18'.

Run heroku stack in CLI to get the info. By default, it is set to 'heroku-18' which is the latest version and uses Ubuntu 18.04 with PHP 7.2 installed.

If it is on 'heroku-18', use command heroku stack:set heroku-16 to toggle.

P.S: PHP versions 5.6 and 7.0 will reach end-of-life at the end of 2018. No bugfixes, including critical security fixes, will be provided by the PHP maintainers after this date. Users are strongly encouraged to update their applications to the latest version of PHP 7.2 at their earliest convenience. For more information on support timelines for PHP releases, refer to the Supported Versions page on the official PHP website.

Upvotes: 5

dzuelke
dzuelke

Reputation: 2645

You need the right type of version selector. Read https://getcomposer.org/doc/articles/versions.md

In your case, ~7.0.0 allows 7.0.0 or later, but not 7.1.

Remember to update composer.lock after the change, as documented at https://devcenter.heroku.com/articles/php-support#selecting-a-runtime (read that entire section; the orange box there actually answers exactly the question you posted here).

You really should update your code though. Support for PHP 7.0 will end in a few days, and the PHP team will no longer provide updates except for security fixes. See http://php.net/supported-versions.php

Upvotes: 2

Soolie
Soolie

Reputation: 1797

From Selecting a runtime, you need to use composer.json and specify the PHP version there:

{
  "require": {
    "php": "^5.6.0"
  }
}

In your case, please have:

{
  "require": {
    "php": "7.0.0"
  }
}

Upvotes: 3

Related Questions