Home > Software design >  PHP Version of Laravel
PHP Version of Laravel

Time:09-19

Does a Laravel project require 2 versions of PHP ?

I am working on a Laravel project. I have 2 versions of PHP in my computer. If I set PHP version 8.1 and run composer update I am getting below error.

enter image description here

If I set PHP version 7.4 and run composer update I am getting below error.

enter image description here

What will be the solution ?

CodePudding user response:

No, it does not require more than one PHP version, yet you need to be consistent. In fact your problem is not Laravel related at all. It's composer thing.

For me it looks like you installed your project and dependencies using PHP 8.1 in first place and how you want to target 7.4. But composer update running on PHP 7.4 will fail (as you saw) because it simply cannot handle downgrade. Also some of your dependencies are already pulled in PHP 8 only version (as error message said) and again, composer do not handle such case either.

If your target version is 7.4 (note Laravel 8 is last version supporting PHP 7), then I'd suggest to simply remove completely vendor/ folder and composer.lock file, then run composer install using PHP 7.4 to re-set up the project and dependencies using that version of the environment. I'd then try stick to PHP 7.4 version for future composer invocations to avoid similar problems.

PS: I personally have aliases like composer56, composer74, composer81 setup on my dev machine specifically for that reason.

CodePudding user response:

On Linux I use update-alternatives. You can do sudo update-alternatives --config php , and after that you can check your default version by PHP -v If it does not work please run these commands :

composer clear-cache
composer self-update
composer update --ignore-platform-reqs

I hope it helps you.

  • Related