-1

I'm trying to update Laravel from 9 to 10. I've followed the upgrade documentation and when I hit composer update, it gave me this error:

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 8.0.28.

In the composer.json I already changed the php version on two places:

"require": {
    "php": "^8.1.0",
},

and

"config": {

    "platform": {
        "php": "8.1.0"
    }
},

When I check my PHP with:

php -v

It shows that I'm using the correct version of PHP.

PHP 8.1.17 (cli) (built: Apr 11 2023 19:20:16) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.17, Copyright (c) Zend Technologies

I also cleared all the caches to Laravel and tried with:

composer dump-autoload

and I'm getting this error:

[ErrorException]
  Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 8.0.28.

I've investigated even more and I found out when I try with this command:

composer -vvv about

The first line of the result looks like this:

Running 2.2.9 (2022-03-15 22:13:37) with PHP 8.0.28 on Linux / 3.10.0-1160.53.1.el7.x86_64

So, this means somehow Composer still runs PHP 8.0, instead of PHP 8.1.

How can I force Composer to use the proper version of PHP?

miken32
  • 42,008
  • 16
  • 111
  • 154
user2519032
  • 819
  • 1
  • 18
  • 34
  • Linux, windows, macOS... It makes a difference in this case :). If linux: https://www.cyberciti.biz/faq/how-to-tell-and-force-composer-to-use-a-specific-php-version-such-as-7-x-or-8-x/ – Wimanicesir Apr 20 '23 at 08:05

1 Answers1

-1

Do you use php artisan serve?

when yes try /usr/bin/php artisan serve this should start php 8.1.17

ABJ
  • 37
  • 1
  • Please add some explanation to your answer such that others can learn from it. As far as I know, Composer does not use Artisan, so how should running your command help when `composer update` shows an error message? – Nico Haase Apr 20 '23 at 08:28
  • Excellent answer and this solved my issue. When I run your written command and after that I tried with composer -vvv about, it actually shows the right version of PHP and I got no errors anymore. Thank you very much! – user2519032 Apr 20 '23 at 08:29