Home > database >  What would be the proper steps to upgrade laravel version 5 to latest version 9
What would be the proper steps to upgrade laravel version 5 to latest version 9

Time:12-12

I have an old project which I developed in Laravel 5.3 and I want to upgrade the project to Laravel v9. What are the steps to upgrade?

What I have seen so far on the internet and from my knowledge:

Upgrade to each higher version step by step e.g 5.3 to 5.4 ... 6 to 7 to 8 to 9

I am running php 8 on my macos. And currently, my code is not running because of deprecated methods in php 5.6 that my Laravel 5.3 is using.

How to upgrade properly?

My composer.json file is

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*",
        "appzcoder/crud-generator": "^2.0",
        "laravelcollective/html": "5.3.*",
        "doctrine/dbal": "^2.5",
        "maatwebsite/excel": "~2.1.0",
        "predis/predis": "~1.0",
        "guzzlehttp/guzzle": "~4.0",
        "laravel/scout" : "^2.0",
        "algolia/algoliasearch-client-php": "^1.17",
        "fx3costa/laravelchartjs": "^2.2",
        "gloudemans/notify": "^1.0",
        "pda/pheanstalk": "~3.1"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "allow-plugins": {
            "kylekatarnls/update-helper": true
        }
    }
}

CodePudding user response:

The latest dependencies can be found in composer.json from https://github.com/laravel/laravel.

There are many more things to do:

  • Traverse the repository above and check all files for changes with your own project. Often times they contain backwards compatible changes (like new keys in config/xxx.php files) but sometimes you need to change certain function definitions because names, parameters or interfaces have changed.
  • (optional) update the css/js build process since it has been revised many times (I believe the default build tool now is "Vite"; older implementations still use "Laravel Mix").
  • Traverse the upgrade guides https://laravel.com/docs/9.x/upgrade. You could start with all the high impact changes to fix the bulk of the issues. If you have enough knowledge of the framework you can probably just update the dependencies (skipping all upgrade guides), analyze the exception traces and work from there.
  • Test every functionality of your website (Laravel 5.3 is from 2016 so there could be quite some technical debt in fixing all errors).
  • Hopefully you have some tests written to automate some if this testing process :)

Note that this repository is the blueprint of a Laravel project. The actual framework resides in https://github.com/laravel/framework (it is the dependency that can be found in the composer.json above).

There is sadly no clearcut answer to do all this. If you want to do it slowly but surely you could traverse each and every upgrade-guide (and test in between) but it could take quite some time.

  • Related