![Upgrading Laravel to 8.x, 9.x or 10.x Upgrading Laravel to 8.x, 9.x or 10.x](https://jaypatchala.com/wp-content/uploads/2023/07/laravel-upgrade.png)
Upgrading Laravel to 8.x, 9.x or 10.x
A guide for upgrading Laravel from older to newest versions
Some of you may be still running Laravel 5.x, 6.x or 7.x for whatever reasons and not yet upgraded to the latest ones, now Laravel 10.x. I had an old application still running on 5.8, and was able to successfully upgraded it to 9.x. I am sharing some of the steps involved. Please note that the process can vary based on your application and environment, these are only general steps involved.
Some Key Considerations
There are two main approaches to upgrading Laravel, its up to you to decide on which one to follow
- Incremental upgradation: You upgrade to the next stable and best version till you reach your target version of Laravel. For example, if you have a version 5.8 and looking to upgrade to 9.x, the upgradation path is 5.8 -> 6.0 -> 7.0 -> 8.0 -> 9.x. It takes several steps and at each step you check and verify that upgrade is successful and working.
- Fresh installation of the latest version and migrating your code: It can make sense if you are using oldest versions of Laravel to the latest versions, where a lot has changed and you may be looking to exploit some of the advanced features in teh latest versions. Its expensive and may require a lot of code rewriting, but its worth the effort in the end.
Another consideration is server requirements. As you can see from the table below, different Laravel versions require corresponding versions of PHP and other modules
Laravel Version | PHP Version | High Impact Changes |
5.x | PHP >= 5.4, PHP < 7 | Separate environment config file |
6.x | PHP >= 7.2.5 | Authorized Resources & String & Array Helpers |
7.x | PHP >= 7.2.5 with more extensions | Authentication Scaffolding Date Serialization |
8.x | PHP >= 7.3 | Model Factories Pagination Defaults Seeder & Factory Namespaces |
9.x | PHP >= 8.0 | Updating Dependencies Flysystem 3.x Symfony Mailer |
10.x | PHP >= 8.1 | Updating Dependencies Updating Minimum Stability |
The important process is meeting requirements for each version and handling high impact changes to ensure a smooth transition.
Note: Before proceeding with the update, make sure you have a complete backup of your application files and database to avoid any data loss or irreversible changes.
Upgrading Laravel Step by Step – from one version to the next one
If you have chosen the fresh installation method, you should talk to your developer or hire me about the process, cost and timelines. You can also add new features taking advantage of Laravel’s advanced functionality.
The following steps are meant for those who want to follow the increments method, from one version to the next version.
Step 1: Update Composer
You should have the latest version of Composer. You can update Composer by running the following command:
![](https://jaypatchala.com/wp-content/uploads/2023/07/composer-update.png)
Step 2: Follow Laravel Documentation
The official Laravel upgrade instructions can be found at https://laravel.com/docs/master/upgrade and for each step of upgrading Laravel (e.g., 5.x to 6.x, 6.x to 7.x, 7.x to 8.x, etc.), there is a separate resource that you can follow. It is very important to understand the changes from the previous versions and their potential to break your application. After upgrading to each new version, keep a backup of that version, before proceeding to the next higher version.
Step 3: Update Dependencies
Update the composer.json file to set the target Laravel version. For example, when updating from version 5.x to 6.x, chnge the line “laravel/framework” version to “^6.0”.
After making changes, run the composer update command to as shown below, to update all dependencies.
![](https://jaypatchala.com/wp-content/uploads/2023/07/composer-update-2.png)
4. Update Config Files
Laravel introduced changes to config files and folder structures. Check the corresponding version’s Laravel upgrade page for any changes to config, environment variables and folder structures.
Step 5: Check Service Providers and Aliases
In newer Laravel versions, some service providers and aliases might be deprecated or changed in the config/app.php file. Read the Laravel upgrade guide carefully and make changes as described.
Step 6: Deprecations and changes
Over a period of time, some methods or properties may have changed or deprecated. For example string and array methods (v5.8), $dates property (v10.x), Swift Mailer to Symphony Mailer (v9.x) etc.
Conduct an audit and review of your codebase for any such deprecated code that may affect your application’s functionality. Make the necessary code changes and refactor your code as per the new standards and conventions.
Step 7: Updating 3rd party Packages
Every application depends on several 3rd party packages and libraries. Some of these libraries release compatible versions as soon as a new Laravel update is announced and some packages lag behind. When upgrading Laravel to the each subsequent version, check if if the compatible versions of packages available or not. Update the versions in your composer.json file and run composer update to update these packages. If a package is not compatible, approach the developer and enquire about the next update.
Step 8: Test Test test
Testing your application thoroughly after each Laravel upgrade is the only way to make sure that there are no errors, unexpected behaviors, or regressions have crept in during the update.
Step 9: Repeat for Subsequent Versions
Repeat this incremental process (6.x to 7.x, 7.x to 8.x etc), till you reached your target Laravel version or the current latest version (10.x)
Upgrading Laravel application is essential to exploit its new features, performance improvements, and security enhancements. It will significantly improve your application’s performance and user experience. However, if you are not careful about planning the upgradation, it can create some problems. Always take the time to test your application thoroughly after each update to ensure its stability and functionality.
If you need any help with Laravel Upgradation, you can hire me.