Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

_christoph's avatar

Upgrade existing project from Laravel 8 to 9

So as a preface to my question, I started out with Laravel 8. I'm a newbie. :p Please bear that in mind.

Ok, so most of what I've read about upgrading to Laravel 9, it is said that you should just create a new project and just copy over my project-specific files to that new directory. That's all well and fine but is not practical in my situation. I'm wondering if there is documentation somewhere out there that details the steps that are necessary to take in order to update my existing project.

I've seen this page in the Laravel docs and it does lay out some changes that you need to make to your composer.json file but then what? And is that all there is? Then just running composer upgrade/update? Are there any other steps I would need to take to get my project to run on Laravel 9? I understand that I may need to change some of the code in my project-specific files and all of that is laid out on the above-referenced page. But that is my code. I want to make sure that everything else in my project is running Laravel 9 code.

The reason I'm asking all of this is because I did take those steps on the above page and these are the changes I made to my composer.json:

    "inertiajs/inertia-laravel": "^0.5.4",
    "laravel/framework": "^9",
    "spatie/laravel-ignition": "^1.0",
    "nunomaduro/collision": "^6.0",

After all of that I ran composer upgrade. It made it through all the download, removing, upgrading, and installing but when it got to needing to run artisan for some reason, this is what I'm seeing:

54 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Error 

  Undefined constant Illuminate\Http\Request::HEADER_X_FORWARDED_ALL

  at vendor/fideloper/proxy/config/trustedproxy.php:48
     44▕      * - 'HEADER_X_FORWARDED_AWS_ELB' (If you are using AWS Elastic Load Balancer)
     45▕      *
     46▕      * @link https://symfony.com/doc/current/deployment/proxies.html
     47▕      */
  ➜  48▕     'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,
     49▕ 
     50▕ ];
     51▕ 

      +9 vendor frames 
  10  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Fideloper\Proxy\TrustedProxyServiceProvider))

      +5 vendor frames 
  16  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

So now my project is pretty much dead in the water.

I know that a product called Laravel Shift exists but a) I'd like to learn how to upgrade manually and, more importantly, b) I don't have a github repository (and I'd rather not create one solely for this purpose) for my project. So I'm wondering if there is a guide that lays out the upgrade process step by step to get my existing project running on Laravel 9. Because whatever it is that I am (or am not) doing is wrong and I'd like to make it right.

Thank you

Christoph

0 likes
17 replies
tykus's avatar

it is said that you should just create a new project and just copy over my project-specific files to that new directory

Not necessary.

I've seen this page in the Laravel docs and it does lay out some changes that you need to make to your composer.json file but then what? And is that all there is? Then just running composer upgrade/update? Are there any other steps I would need to take to get my project to run on Laravel 9?

Follow the rest of the Upgrade Guide.

t made it through all the download, removing, upgrading, and installing but when it got to needing to run artisan for some reason, this is what I'm seeing:

Read the section on Trusted Proxies immediately after this link (it is not linked itself) - you need to make changed to the TrustedProxies middleware.

_christoph's avatar

@tykus

  • I figured it wasn't necessary to create a new project. Just that was the only recommendation I was seeing.

  • The rest of the upgrade guide details changes that I need to make to any of my code (most of those changes don't affect me). But all of that assumes that I've upgraded from 8 to 9. And so far it doesn't seem like that upgrade is successful.

  • I saw the section about the Trusted Proxies but, again, it seemed like that was something that I needed to do after upgrading to 9. The error I detail above occurs during what seems to be the upgrade process.

tykus's avatar

@_christoph

But all of that assumes that I've upgraded from 8 to 9

Those changes are part of the upgrade to v9 - the composer part is relatively minor.

The error I detail above occurs during what seems to be the upgrade process.

I don't think I have ever run php artisan in the middle of an upgrade process...

_christoph's avatar

@tykus Yes, I understand that they are part of the upgrade to v9. But all of those changes are based upon the project running the Laravel 9 framework. If your project isn't running Laravel 9 then those changes will break things because they are predicated on code that isn't actually there. So getting the framework upgraded from 8 to 9 is crucial and that is the largest part of my dilemma -- I can't seem to get it from 8 to 9.

Is it the case that I have to make those changes to my existing code before I try to upgrade the framework to 9? If so then there was no mention of that fact and that demonstrates the need (at least for newbies like me) for a step by step guide to upgrade.

To me (again, newbie) it seems to me like step 1 should be changing your composer.json file and upgrading all the packages (including laravel/framework). Then, what follows as steps 2+, should be all the changes to your code laid out on the upgrade page (e.g, the PHP Return Types). But I did that and I'm getting the error illustrated in my original post. So I must be wrong and I should be doing something before changing the composer.json file and upgrading. But I don't know what that is.

I don't think I have ever run php artisan in the middle of an upgrade process...

I didn't, composer (or something it was working with) did. See my original post. It happened right after the message about the package suggestions.

_christoph's avatar

@tykus I made all of those changes (relevant to my project) and even after running the composer update I was still getting the error.

There was one step that I was missing and it's only obliquely referenced in the upgrade guide -- I needed to remove "fideloper/proxy": "^4.4", from my composer.json file. The upgrade docs did mention changing the code but it didn't reference that change to composer.json the way that it did other changes to that file further up the page. So a newbie like me could (and in my case did) miss that. Once I made that change everything else seemed to run smoothly.

Thanks for all your replies.

2 likes
Snapey's avatar

the only recommendation I was seeing.

where? Who publishes this rubbish? name and shame !

EE's avatar

Similar problem here! Upgrading from L8 project to L9. I followed upgrade guide and updated dependencies to latest but no luck! composer update can only finishes when I remove "fideloper/proxy": "^4.4", from composer. Which I can see that "fideloper/proxy": "^4.4" no longer required on new L9 project.

vendor/fideloper/proxy/config/trustedproxy.php:48
     44▕      * - 'HEADER_X_FORWARDED_AWS_ELB' (If you are using AWS Elastic Load Balancer)
     45▕      *
     46▕      * @link https://symfony.com/doc/current/deployment/proxies.html
     47▕      */
  ➜  48▕     'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,
     49▕ 
     50▕ ];
1 like
_christoph's avatar

@EE Yeah, I was finally able to figure it out. It definitely wasn't at all apparent in the guide. :/

robdesilets's avatar

@_christoph Spent all morning on this myself, finally arriving to delete that from the composer.json. If the Laravel docs talked about removing this from the composer.json as well as updating the TrustedProxies path would have saved a lot of time :(

1 like
_christoph's avatar

@shaungbhone It's really good to know that this newbie wasn't the only person who experienced this issue...

1 like
Hadayat's avatar

If the above answer does not work for you and you are getting the same error, execute one more line for removing the fideloper/proxy from composer.json.

// Before...
protected $headers = Request::HEADER_X_FORWARDED_ALL;
 
// After...
protected $headers =
    Request::HEADER_X_FORWARDED_FOR |
    Request::HEADER_X_FORWARDED_HOST |
    Request::HEADER_X_FORWARDED_PORT |
    Request::HEADER_X_FORWARDED_PROTO |
    Request::HEADER_X_FORWARDED_AWS_ELB;

This will remove the proxy from the composer.json and the exception will be gone.

composer remove fideloper/proxy

it's properly mentioned in the laravel 9 upgrade guide. https://laravel.com/docs/9.x/upgrade#the-assert-deleted-method

Please or to participate in this conversation.