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
"spatie/laravel-ignition": "^1.0" in your application’s
"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.
app/Http/Middleware/TrustProxies.php file, update
use Fideloper\Proxy\TrustProxies as Middleware to
use Illuminate\Http\Middleware\TrustProxies as Middleware.
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.
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.