PHP
Upgrading Laravel to 8.x, 9.x or 10.x

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 VersionPHP Version High Impact Changes
    5.xPHP >= 5.4, PHP < 7Separate environment config file
    6.xPHP >= 7.2.5Authorized Resources &
    String & Array Helpers
    7.xPHP >= 7.2.5 with more
    extensions
    Authentication Scaffolding
    Date Serialization
    8.xPHP >= 7.3Model Factories
    Pagination Defaults
    Seeder & Factory Namespaces
    9.xPHP >= 8.0Updating Dependencies
    Flysystem 3.x
    Symfony Mailer
    10.xPHP >= 8.1Updating 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:

    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.

    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.

    Disclosure: Affiliate Disclosure for Jay Patchala's Blog On my website https://jaypatchala.com, e will occasionally evaluate or mention products and services. If we believe a product or service is good, and the merchant selling it provides an affiliate programme, we have no problem referring others to it via an affiliate link, which means we may receive a commission or other kind of income if you purchase the product we promote. Certain items and links to products/services are affiliate links, and any purchases you make may result in a commission for me. we am paid to give my honest opinion on products and/or services on occasion. You will not be charged any additional fees as a result of this. These items and services are mentioned because we believe in them and wish to assist you in improving your life. we only endorse products or services that we believe will benefit you. Of course, full disclosure: Making Sense of Cents is a for-profit business, which means we do make money from it. To make things easier for both of us, assume that any links to products or services are affiliate links and that we will be compensated if you buy something. Our disclosure page is created with the help of RaptorKit's' Free Affiliate Disclosure generator. Affiliate links are disclosed in accordance with the Federal Trade Commission's standards. If you have any further questions, feel free to mail us on kumar@jaypatchala.com Thanks!
    Follow by Email
    LinkedIn
    Share
    Instagram