PHP Version of Laravel

Viewed 76

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 ?

1 Answers

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 solely a composer related thing.

For me it looks like you installed your project and alle the dependencies using PHP 8.1 in first place and now you want to lower the target version to 7.4. But composer update running on PHP 7.4 will fail (as you saw) because it simply cannot handle downgrade installed project to match new environment. Also some of your dependencies are already pulled in PHP 8 only version (as error message said) and 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 set up wrappers like composer56, composer74, composer81 setup on my development machine specifically for that reason.

Related