I have a Laravel backend providing an API to my Angular frontend. As a local environment I use Vagrant with Laravel Homestead. My Laravel version is 8 (8.83.27). Everything is working just fine.
But when I try to upgrade PHP version (to 7.4 or 8.0) by editing my composer.json and running “composer update”, I’m in trouble. All my API routes start responding with CORS errors, and preflight requests respond with 502. If I revert the changes and run “composer update” again with the previous configuration, it works correctly, as it used to. I’m not sure if this is about the environment, some configurations, or the dependencies. Any help on this one?
This is my composer.json before editing. Works as it is, but leading to CORS errors after upgrading PHP and running composer update.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"require": {
"php": "^7.3|^8.0",
"doctrine/dbal": "^3.3",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.19",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^8.0",
"laravel/legacy-factories": "^1.1",
"laravel/passport": "^10.2",
"laravel/tinker": "^2.0",
"laravel/ui": "^3.0",
"mxl/laravel-job": "^1.2",
"nesbot/carbon": "^2.0.0",
"nunomaduro/collision": "^5.3",
"symfony/http-client": "^5.4",
"symfony/mailgun-mailer": "^5.4"
},
"require-dev": {
"composer/composer": "^2.2",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
"App\": "app/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"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"
],
"post-update-cmd": [
"Illuminate\Foundation\ComposerScripts::postUpdate"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true,
"platform": {
"php": "7.3"
}
}
}
I tried to change the following
“require”: { “php”: “^7.3|^8.0”, => “php”: “^7.4|^8.0”,
and
“platform”: { “php”: “7.3” => “php”: “7.3”
Which lead to the following package updates:
Updating dependencies
Lock file operations: 5 installs, 13 updates, 0 removals
- Upgrading carbonphp/carbon-doctrine-types (1.0.0 => 2.1.0)
- Upgrading composer/pcre (2.1.1 => 3.1.1)
- Locking dflydev/dot-access-data (v3.0.2)
- Upgrading doctrine/dbal (3.3.8 => 3.8.3)
- Upgrading fakerphp/faker (v1.20.0 => v1.23.1)
- Upgrading firebase/php-jwt (v6.4.0 => v6.10.0)
- Locking lcobucci/clock (2.0.0)
- Upgrading lcobucci/jwt (3.4.6 => 4.3.0)
- Upgrading league/commonmark (1.6.7 => 2.4.2)
- Locking league/config (v1.2.0)
- Upgrading league/mime-type-detection (1.12.0 => 1.15.0)
- Upgrading league/uri (6.5.0 => 6.7.2)
- Locking nette/schema (v1.2.5)
- Locking nette/utils (v3.2.10)
- Upgrading nikic/php-parser (v4.18.0 => v5.0.2)
- Upgrading psr/container (1.1.1 => 1.1.2)
- Upgrading psy/psysh (v0.11.22 => v0.12.0)
- Upgrading ramsey/collection (1.2.2 => 1.3.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 5 installs, 13 updates, 0 removals
- Downloading nikic/php-parser (v5.0.2)
- Upgrading psr/container (1.1.1 => 1.1.2): Extracting archive
- Upgrading composer/pcre (2.1.1 => 3.1.1): Extracting archive
- Upgrading doctrine/dbal (3.3.8 => 3.8.3): Extracting archive
- Upgrading ramsey/collection (1.2.2 => 1.3.0): Extracting archive
- Upgrading carbonphp/carbon-doctrine-types (1.0.0 => 2.1.0): Extracting archive
- Upgrading league/mime-type-detection (1.12.0 => 1.15.0): Extracting archive
- Installing nette/utils (v3.2.10): Extracting archive
- Installing nette/schema (v1.2.5): Extracting archive
- Installing dflydev/dot-access-data (v3.0.2): Extracting archive
- Installing league/config (v1.2.0): Extracting archive
- Upgrading league/commonmark (1.6.7 => 2.4.2): Extracting archive
- Upgrading fakerphp/faker (v1.20.0 => v1.23.1): Extracting archive
- Upgrading league/uri (6.5.0 => 6.7.2): Extracting archive
- Installing lcobucci/clock (2.0.0): Extracting archive
- Upgrading lcobucci/jwt (3.4.6 => 4.3.0): Extracting archive
- Upgrading firebase/php-jwt (v6.4.0 => v6.10.0): Extracting archive
- Upgrading nikic/php-parser (v4.18.0 => v5.0.2): Extracting archive
- Upgrading psy/psysh (v0.11.22 => v0.12.0): Extracting archive
I tried to upgrade my PHP version by editing composer.json and running composer update. The upgrade itself goes ok but all routes start responding with CORS errors, and preflight with 502.