Upgrading Your Laravel Application from PHP 7.2 to PHP 8
Moving your Laravel app from PHP 7.2 to PHP 8 can boost performance, add new features, and improve security. However, you need to plan and execute the upgrade carefully to avoid is…

Moving your Laravel app from PHP 7.2 to PHP 8 can boost performance, add new features, and improve security. However, you need to plan and execute the upgrade carefully to avoid issues. Here’s a simple guide to help you upgrade your Laravel app to PHP 8.
Step 1: Check Compatibility
Before you start, make sure your Laravel version and all your app’s dependencies work with PHP 8. Laravel 6 and newer versions are compatible, but older versions are not. Also, check if the third-party packages you use are compatible.
Check Your Laravel Version:
php artisan --version
Check Dependencies:
Look at your composer.json file and verify the dependencies' PHP 8 compatibility from their documentation or repositories.
Step 2: Update Composer Dependencies
Next, update your app’s dependencies to versions that support PHP 8. Edit your composer.json file to set the PHP version and update package versions.
Update PHP Requirement:
Open composer.json and change the PHP requirement:
"require": {
"php": "^8.0",
// other dependencies
}
Update Laravel and Other Packages:
Update Laravel and other packages to the latest compatible versions:
"require": {
"laravel/framework": "^8.0",
// other dependencies
}
Run Composer Update:
After editing composer.json, run:
composer update
Step 3: Test Locally on PHP 8
Before deploying to production, test your app locally on PHP 8.
Install PHP 8 Locally:
The steps depend on your OS. For example, on Ubuntu:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php8.0
Switch to PHP 8:
Ensure your local server uses PHP 8:
sudo update-alternatives --set php /usr/bin/php8.0
— El Hassania Hechadi
