Ligonsker's avatar

Updating Laravel versions

Hello,

I need to upgrade Laravel from version 7 to 10 but there are many conflicts due to long time of not using Composer and editing the composer files manually. I get all sorts of errors such as errors due to "partial update" or "fixed versions in composer.lock" .. etc.

Can I just delete composer.lock and do composer install with the correct packages of Laravel 10? Or that is not a good idea?

Thanks

0 likes
15 replies
LaryAI's avatar
Level 58

It is not recommended to delete the composer.lock file and do a fresh composer install as this can cause compatibility issues with your dependencies. Instead, you should follow the Laravel upgrade guide for each version incrementally until you reach version 10. This will ensure that all dependencies are updated correctly and any breaking changes are addressed along the way.

Here are the general steps to follow:

  1. Backup your project files and database.
  2. Update your composer.json file to require the new version of Laravel.
  3. Run composer update to update your dependencies.
  4. Follow the Laravel upgrade guide for the version you are upgrading to. This may involve updating configuration files, routes, and other code changes.
  5. Test your application thoroughly to ensure everything is working as expected.
  6. Repeat steps 3-5 for each version increment until you reach version 10.

Here is an example of updating from Laravel 7 to 8:

# Update composer.json to require Laravel 8
"require": {
    "php": "^7.3|^8.0",
    "laravel/framework": "^8.0",
    ...
}

# Run composer update
composer update

# Follow the Laravel 8 upgrade guide
https://laravel.com/docs/8.x/upgrade

# Test your application thoroughly

Repeat these steps for each version increment until you reach version 10.

jlrdw's avatar

I have found it as fast or faster to create a new project and migrate the MVC over. But just suggestion.

If upgrading, go through each upgrade guide to manually update laravel. Laravel has to be manually upgraded then composer will upgrade the framework.

From upgrade guide:

Finally, examine any other third-party packages consumed by your application and verify you are using the proper version for Laravel 10 support.

Ditto for other laravel versions.

1 like
Ligonsker's avatar

@jlrdw So I create a new Laravel 10 project and copy over the files? (I started doing it but then thought I should first try the upgrade guides)

martinbean's avatar

@ligonsker What do you mean, “editing the Composer files manually”? Why have a dependency management system like Composer in place if you’re not actually going to use it?

1 like
Ligonsker's avatar

@martinbean Yes but we had the network closed for over a year due to security issues so some developers came up with weird solutions to make things work (We did not really have composer for a long time and had to somehow add packages to the existing project)

jlrdw's avatar

@Ligonsker My suggestion is:

Besides the packages required by laravel, don't use outside packages. There are a couple of exceptions of course for known safe (developer has known integrity) packages.

Just me, but I don't trust all the packages from Github.

1 like
martinbean's avatar

@Ligonsker So your network was locked down because someone didn’t trust a dependency manager to install dependencies, so you just “manually” installed the dependencies any way, thus making the process of “locking down the network” completely moot when the code was added to projects any way…?

1 like
Ligonsker's avatar

@martinbean They tried to manually install each package (and its dependencies) one-by-one (after manually checking and scanning each package) 😅 then tried to add that to the project. that didn't work too well

Ligonsker's avatar

@jlrdw thanks. Using only a few and all widely used (And only after scanned against all known vulnerabilities databases such as the composer DB and the US govt. CVE DB - it will automatically be blocked if any small thing is detected also).

Do you think the following will work to jump from Laravel 7 to 10 for example: Since I do not have many 3rd party packages, can I:

  1. Install a clean Laravel 10 project
  2. Delete composer.json and composer.lock from the the existing Laravel 7 project
  3. Copy the composer.json from the clean Laravel 10 project to the existing Laravel 7 project
  4. Run composer update (or install) on the Laravel 7 project
  5. manually install the few 3rd party packages (using require)
  6. Follow the upgrade guides from 7>8>9>10 to update any code-related breaking change

will that work?

jlrdw's avatar

@Ligonsker I think just doing a new project would be easier, just my opinion.

And copy your models, views, controllers, custom classes over. Then fix routes.

I also use a merge tool if upgrading, but you really have to know what you are doing.

I don't recommend this unless some practice has been done first.

https://laracasts.com/discuss/channels/guides/update-upgrade-laravel-then-framework

But you still have to manually update dependencies.

Then are you going to use vite or mix, I use neither, so an upgrade is a lot faster for me.

1 like
Ligonsker's avatar

@martinbean also to be honest, if you've seen the recent packagist compromising, I wouldn't trust composer completely either. And it's not that unknown packages were compromised, but very known packages. Lucky the attacker did that to get a job at Cyber security and didn't do malicious things. But really, gaining access to change composer packages like that is scary if your data is sensitive.

And ok you can say it was patched, but if these things happen once, you just don't trust it the same again

martinbean's avatar

@Ligonsker So what‘s the alternative? Just write everything from scratch? And if so, where do you stop? Are you running Windows? Or macOS? Because they’re not infallible to being compromised either. So are you going to start writing your own operation system from scratch?

1 like
Ligonsker's avatar

@martinbean Eventually there was a solution - to use a similar thing to Private Packagist, it's a paid system that you set as the repo instead of packagist in your global composer config, then all traffic goes through this system (then you set packagist: false). This system then connects to packagist as well, but before it lets you download anything, it scans it against all the vulnerabilities known to it (to the company running this system), it's pretty good, it blocks the download and tells u exactly the vulnerability of the package (And if you try to install a project like Laravel it will block the project installation and list all the vulnerable packages there). It links you to where source of the vulnerability - some links were to GitHub, some links were to the NIST CVE website

martinbean's avatar

it scans it against all the vulnerabilities known to it (to the company running this system)

@Ligonsker And what’s to say this system and company won‘t be compromised? Or is trustworthy to begin with…?

1 like
Ligonsker's avatar

@martinbean true, but it's at least a known system and also this way the security team can have everything monitored in a centralized place so less likely to escape under their radar like when letting everyone do what they want (I saw the dashboard it's pretty cool). I think many companies use it, it seem to also have a free version - if you heard of Sonatype (In their website there's a list of some big companies using it, if you can believe this list). It's actually the one that blocked the recent compromised packages and gave links to the reasons

Please or to participate in this conversation.