Chron's avatar
Level 6

How to upgrade laravel 5.8 to 9?

I'm having a trouble upgrading laravel. It says that I need to upgrade it sequentially. So I tried updating it to v6.0 first, but I got this error.

>  composer update

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires php 7.4.* but your php version (8.1.5) does not satisfy that requirement.
  Problem 2
    - laravel/framework[v5.8.0, ..., 5.8.x-dev] require php ^7.1.3 -> your php version (8.1.5) does not satisfy that requirement.
    - Root composer.json requires laravel/framework 5.8.* -> satisfiable by laravel/framework[v5.8.0, ..., 5.8.x-dev].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
0 likes
7 replies
tykus's avatar

Your PHP version exceeds the Laravel version requirements:

laravel/framework[v5.8.0, ..., 5.8.x-dev] require php ^7.1.3 -> your php version (8.1.5) does not satisfy that requirement.

Install the required PHP version.

Chron's avatar
Level 6

@tykus I installed php74 and this is what I got:

Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In PackageManifest.php line 122:

  Undefined index: name


Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Chron's avatar
Level 6

I changed the laravel/framework in composer.json to "6.0.*" and I got this:

Problem 2
    - laravel/framework[v6.0.0, ..., v6.0.4] require php ^7.2 -> your php version (8.1.5) does not satisfy that requirement.
    - Root composer.json requires laravel/framework 6.0.* -> satisfiable by laravel/framework[v6.0.0, ..., v6.0.4].

vybeauregard's avatar

That's gonna be a pretty big lift without any automation. The framework has changed quite a bit since 5.x with regard to deprecations, added/removed dependencies, etc. Consider a tool like https://laravelshift.com/ to ease the transition. Countless devs report it's worth the financial cost.

1 like
eterlinden's avatar

Hi @chron,

First, you must know that it will have to be an incremental process.

You two things you must consider.

  1. Upgrading Laravel
  2. Changing your code to correctly reflect and run under higher PHP versions.

I can suggest a great tool, which is free, that can help you upgrade your old code.

https://github.com/rectorphp/rector

It's still a bit of lifting, especially if you lack the PHP experience to cope with the language changes.

I do this helps you in some way.

Cheers.

JeffreyWay's avatar

If you don't want to use a service like Laravel Shift, then I would highly recommend installing a fresh Laravel app, and then incrementally migrating your application code over.

9 likes
jlrdw's avatar

If you do upgrade, make sure laravel is correctly upgraded prior to upgrading / updating the framework.

Either:

  • Follow each upgrade guide
  • Or use a merge tool but still reading each upgrade guide

But a new app is easier. And you are aware that laravel is always manually upgraded, right?

Please or to participate in this conversation.