How to Upgrade from PHP7.4 to PHP8.2 and Laravel6 to Laravel10【Laravel】
Thank you for your continued support.
This article contains advertisements that help fund our operations.
Table Of Contents
⇨ Click here for the table of contents for Laravel articles
Summary of how to update a Laravel project from PHP7.4 to PHP8.2 and from Laravel6 to Laravel10.
From Laravel6 to Laravel7
Instead of upgrading directly from 6 to 10, we will do it step by step.
Update composer.json
Find the following items already written in composer.json and update the versions
"laravel/framework": "^7.0",
"nunomaduro/collision": "^4.1",
"phpunit/phpunit": "^8.5",
"laravel/tinker": "^2.0",
"facade/ignition": "^2.0",
Commands
Pray while
composer update
Bug Occurrence
Using version ^1.0 for laravel/ui
./composer.json has been updated
Running composer update laravel/ui
~~~
Problem 1
- laravel/ui[v1.1.0, ..., 1.x-dev] require illuminate/console ^7.0 -> found illuminate/console[v7.0.0, ..., 8.x-dev] but it conflicts with another require.
Such an error occurred.
On further investigation, it seemed that the version 1 of laravel/ui was not suitable.
Therefore, it was necessary to upgrade to laravel/ui 2.0^ for Laravel7.
Additional lines in composer.json
Similar to before, modify the following item
"laravel/ui": "2.*",
Bug Occurrence
Your requirements could not be resolved to an installable set of packages.
Commands
Pray a lot while
composer update
Further Bug Occurrence
PHP Fatal error: Declaration of App\Exceptions\Handler::report(Exception $exception) must be compatible with Illuminate\Foundation\Exceptions\Handler::report(Throwable $e) in /var/www/html/app/Exceptions/Handler.php on line 37
It seems that the class Exception disappeared and was replaced by Throwable.
Modify app/Exceptions/Handler.php
use Throwable; //Added
//Modify 2 functions
public function report(Throwable $exception)
{
parent::report($exception);
}
public function render($request,Throwable $exception)
{
return parent::render($request,$exception);
}
Commands
Pray while
composer dump-autoload
It worked well.
This completes the update from Laravel6 to Laravel7.
From Laravel7 to Laravel8
Next, let's upgrade from Laravel7 to Laravel8.
Let's proceed believing that nothing will go wrong.
Update composer.json
Modify the versions of the following items.
In my environment, there was no guzzle item.
"laravel/framework": "^8.0",
"guzzlehttp/guzzle": "^7.0.1",
"facade/ignition": "^2.3.6",
"laravel/ui": "3.0",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.0"
Commands
Execute the command while offering earnest prayers.
composer update
It succeeded without any issues.
Check in doubt with the command.
php artisan -v
Laravel Framework 8.83.27
It was a success (the screen was displayed).
Upgrade from Laravel8 to Laravel9
Upgrade from PHP7.4 to PHP8.0
Modify the Dockerfile and rebuild.
FROM php:8.0-fpm
Build and update
docker compose up -d --build
php -v
PHP 8.0.30
PHP was successfully updated without any issues.
Update composer.json
"php": "^8.0",
"laravel/framework": "^9.0",
"nunomaduro/collision": "^6.1",
"facade/ignition": "^2.3.6", → "spatie/laravel-ignition": "^1.0",
Just like before, change the versions of the items and run the commands.
Execute the commands
Offer serious prayers while executing the commands.
composer update
Error Occurrence
Your requirements could not be resolved to an installable set of packages.
Problem 1
- spatie/laravel-analytics[3.10.0, ..., 3.10.1] require php ^7.2 -> your php version (8.0.30) does not satisfy that requirement.
Such an error occurred.
It seems that the dependency of the package "spatie/laravel-analytics" was the cause.
Upgrade spatie/laravel-analytics
spatie/laravel-analytics Documentation
Similarly, modify the version in composer.json and change it to "spatie/laravel-analytics": "^4.0", but the following error occurred.
Problem 1
- spatie/laravel-analytics 4.1.1 requires laravel/framework ^9.41|^10.0
It seems that it needs to be 4.1.1, so
"spatie/laravel-analytics": "^4.1.1",
composer update
This was resolved.
Upgrade "pbmedia/laravel-ffmpeg"
Furthermore, an error occurred due to the dependency of "pbmedia/laravel-ffmpeg".
"pbmedia/laravel-ffmpeg": "^8.0",
composer update
This worked fine!
Upgrade from Laravel9 to Laravel10
Change the versions of the following packages in composer.json
"laravel/framework": "^10.0",
"laravel/ui": "^4.0",
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0",
"fakerphp/faker": "^1.9.1",
"nunomaduro/collision": "^7.1",
Remove the following part
"minimum-stability": "dev",
Run the command
composer update
This completes the process.
Error Occurred Afterward
Error with Filesystem
An error occurred using AWS S3 when checking the existence of a file with exists, if there was an empty string.
League\Flysystem\Filesystem::has(): Argument #1 ($location) must be of type string, null given
The following part caused an error.
$url = Null; //Error with Null
$isFile = $disk->exists($url); //Error with Null
//Continue below
To address this, simply do the following.
$url = Null; //Error with Null
if($url){
$isFile = $disk->exists($url);
//Continue below
}
Conclusion
Thanks to everyone's articles, I was finally able to reach Laravel10.
I have recorded my journey as well, hoping that the bugs encountered by others can be solved with this article.
This is it. I hope it can be helpful to someone.
This blog is supported by clicking on advertisements.
If this was helpful, please, please, thank you very much!
That's all!
Popular Articles