How to Upgrade to Laravel 8

2020-10-15 21:47:56

Local Environment

During this quarantine time, I've decided to upgrade my website to Laravel 7 and then to 8. I've linked the Laravel docs below. I'll be including steps I followed from the docs along with other steps I needed for my setup.

Upgrading Laravel is a fairly straightforward process. You just need to make sure you have the proper requirements and follow the docs and the errors given when you run the upgrade command. That's really all there is to it. Mainly you update your composer.json file to whatever the docs say. I upgraded from 6 to 7 first, and then from 7 to 8. I didn't go from 6 to 8, so I can't comment on how well that would work out, so I just recommend this approach.

Before you really start make sure you're using at least PHP 7.3.0. Here are the commands I followed on MacOS:

brew unlink php@7.2 && brew remove php@7.2 && brew uninstall --ignore-dependencies php@7.2
cd /usr/local/etc/php
rm -rf 7.* (whichever versions you have that aren't 7.3)
brew cleanup
brew install php@7.3
brew link php@7.3

https://laravel.com/docs/7.x/upgrade

When I upgraded from 6 to 7 earlier in quarantine, along with following the docs I had to edit my app/Exceptions/Handler.php file because I was getting errors. I made the following changes:

use Throwable;

public function report(Throwable $exception);
public function shouldReport(Throwable $exception);
public function render($request, Throwable $exception);
public function renderForConsole($output, Throwable $exception);

https://laravel.com/docs/8.x/upgrade

Upgrading to 8 from 7 was easier. I didn't have to edit as much. Again, I just followed the docs and made the following extra changes for the Laravelium plugins I use for my setup in my composer.json file:

"laravelium/feed": "8.0.",
"laravelium/sitemap": "8.0.",

When you're finished with all of this, just run composer update. Use php artisan --version to make sure everything worked. At the time of this article, my setup says Laravel Framework 8.10.0 when I run that command.

Production Environment

I'm running an Apache server so I followed these instructions and commands to update to PHP 7.3.0.

https://www.cloudbooklet.com/how-to-install-php-7-3-on-ubuntu-18-04/

sudo apt install php7.3 php7.3-cli php7.3-common
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.3
sudo apt-get install php7.3-mysql

After you pull all your changes, run php artisan --version again just to make sure everything you just did is live.

Conclusion

Now you should be good to go! Even though was easier for me to upgrade from 7 to 8 than it was from 6 to 7, each time really isn't that difficult. I think that's just a testament to how much work and consideration is put into Laravel. If you're looking for a new framework, I really recommend Laravel.

Updated at: 2020-10-27 10:20:41

Tags: development software technology laravel php


Read More From development