Recently I was working on a Laravel 7 project. I have some other Laravel 7 projects running at the shared hosting. Sometimes it is very hard to keep the different Laravel versions in shared hosting. It was showing the errors
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0" and "< 7.4.0". You are running 7.4.5.
Check Platform:
Composer v2 introduced the new feature Check Platform that checks PHP version before autoload initialized. If set this option to false it will not create the project-path/vendor/composer/platform_check.php in autoloader bootstrap. It loads in bootstrap and terminates the application if the PHP version does not match.
A normal platform_check.php look like
// platform_check.php @generated by Composer $issues = array(); if (!(PHP_VERSION_ID ------>= 70400 && PHP_VERSION_ID < 90000)) { $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0" and "< 9.0.0". You are running ' . PHP_VERSION . '.'; } $missingExtensions = array(); extension_loaded('pdo') || $missingExtensions[] = 'pdo'; if ($missingExtensions) { $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions); } if ($issues) { echo 'Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues); exit(104); }
Solutions:
composer.json:
Add the platform check option in the composer.json config section
"platform-check": false
It will be shown in the config
"config": { "preferred-install": "dist", "sort-packages": true, "optimize-autoloader": true, "platform-check": false },
After that, you need to run
composer update
After the composer update, there will be a file
platform_check.php
will be deleted.
project-path/vendor/composer
Command-line:
You can also true/false platform-check in the command line
Local scope: composer config platform-check false Global scope: composer global config platform-check false
Now it will not show you any error for the PHP version.
Happy Coding!
Reading resources:
https://php.watch/articles/composer-platform-check
https://getcomposer.org/doc/06-config.md#platform-check