Update laravel from 8 to 9
Hello, everyone, as we know on the 8th of Feb 2022, the Laravel version 9(LTS), has been released, and to make our project more stable and less security issue we must have to update our project to laravel version 9.
It took around 30 minutes to update your project from laravel 8 to laravel 9
Follow the below steps to update your project from laravel 8 to 9.
- Remove fideloper/proxy
- Update/add laravel dependencies in composer.json file
- Update Trustedproxy.php middleware
- Test the code integration
Step:1 Remove filedoper/proxy
To remove the filedoper/proxy, please run the below command as laravel 9 did not use filedoper/proxy.
composer remove fideloper/proxy
Step:2 Update/add laravel dependencies.
Go to your composer.json file which is present inside your project root folder.
now do the below changes in your composer.json file
laravel/framework to ^9.0
nunomaduro/collision to ^6.0
now you have to replace facade/ignition
with "spatie/laravel-ignition": "^1.0"
in your application’s composer.json
file.
"facade/ignition": "^2.5", //remove
"spatie/laravel-ignition": "^1.0", // add
when you do the above changes your composer code will look like the below one, I have marked them with red for your reference.
Step:3 Update Trustedproxy.php middleware
If you are upgrading your Laravel 8 project to Laravel 9 by importing your existing application code into a totally new Laravel 9 application skeleton, you may need to update your application’s “trusted proxy” middleware.
Within your app/Http/Middleware/TrustProxies.php
file, update use Fideloper\Proxy\TrustProxies as Middleware
to use Illuminate\Http\Middleware\TrustProxies as Middleware
.
Next, within app/Http/Middleware/TrustProxies.php
, you should update the $headers
property definition:
// 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;
now you have to run the below command in order to update the dependencies.
composer update
Step:4 Test the integration
To check that your laravel version upgraded to laravel 9, please run the below command
php artisan --version
I hope now you can understand how we can upgrade laravel version 8 to laravel version 9.
Hello,
Thank you for the article.
After editing the file app/Http/Middleware/TrustProxies.php you should run “composer remove fideloper/proxy” to remove the this package. It not longer required.
Thanks for your suggestion, now article has been updated
Aperiam reprehenderi.
I think we need to change
nunomaduro/collision
to^6.1 instead of 6.0
refer here https://laravel.com/docs/9.x/upgrade