0

After running sudo apt-get update && sudo apt-get dist-upgrade on my Laravel app, I'm getting this error on the next deployment:

- This package requires php ^7.1.3 but your PHP version (8.1.6) does not satisfy that requirement.

In my composer.json, ^7.1.3 is the specified version. This is my first time running the apt-get update and I don't know why the php version got updated as well.

On each deployment I run

composer install --no-interaction --prefer-dist --optimize-autoloader

How can I downgrade the version to 7.1.3? This happens on an existing app in production and I have to be very careful about it.

Laurel
  • 5,965
  • 14
  • 31
  • 57
Tom Bom
  • 1,589
  • 4
  • 15
  • 38
  • 2
    Hope you backed up the folders. – mardubbles Jun 05 '22 at 00:56
  • I have a snapshot on digital ocean, should I restore it? But should I run the update then? – Tom Bom Jun 05 '22 at 01:00
  • 2
    @TomBomb Yes, I'd restore the snapshot as a first step. I'd then start working on getting your app functional on a more recent version of PHP; PHP 7.1 was discontinued two and a half years ago and no longer receives important security updates as a result. https://www.php.net/eol.php – ceejayoz Jun 05 '22 at 01:01
  • Does this answer your question? [Error "Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement"](https://stackoverflow.com/questions/65454412/error-root-composer-json-requires-php-7-3-but-your-php-version-8-0-0-does-no) – Martin Zeitler Jun 05 '22 at 01:42
  • 2
    Assuming you were on Ubuntu 20.04, `sudo apt-get dist-upgrade` upgraded you to 22.04. If you can restore from your backup run `sudo apt-get update; sudo apt-get upgrade` instead, to update your server to the lastest PHP 7.4 packages instead of PHP 8. – Marshall C Jun 05 '22 at 04:49

2 Answers2

0

The php version installed on your environment should be compatible with your project.

If your project is based on composer package manager (as I see), it can help you to control which php version you need on the server.

In your case I would recommend to restore from the snapshot or just install php 7.1.3 version back.

If you want to use php 7.4/8/8.1 in your project, before you should upgrade your code and project dependencies and ensure, that everything working fine with the desired version of php.

Sergei Shitikov
  • 287
  • 2
  • 12
0

Old topic, but for things like this, I recommend adding the flag to ignore requirements like this. So try:

composer install --no-interaction --prefer-dist --optimize-autoloader --ignore-platform-reqs

There may be incompatibilities with your project using 8.1 instead of 7.1.3, but I doubt it. But still, only do this if you feel confident the PHP version won't be an issue. It's usually better than downgrading, however.

Michael W.
  • 409
  • 7
  • 18