So I want to upload my Laravel 8 project to a web hosting, but when I finished, there was an error message:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 8.0.7. in /storage/ssd4/678/18965678/laravel/vendor/composer/platform_check.php on line 24
After I checked the PHP version on the web hosting, it's only up to the 8.0
version.
I try to downgrade my PHP to 7.4
and 8.0
versions and re-upload to web hosting but the error is getting worse.
I think it is something to do with Composer (?) but I'm not sure what and how to solve it.
Does anyone have a suggestion for this? thank you very much.
*edited the completed error
CodePudding user response:
I think it is something to do with Composer (?) but I'm not sure what and how to solve it.
Yes, you're executing a Composer command, assumable composer install
and you have a composer.lock
file in your project.
What?
When Composer installs from the lock file (named composer.lock
by default), it checks the platform so that you don't install incompatible dependencies unnoticed.
In case there is a deviation in the platform (PHP version, installed PHP extensions and the like) it gives notice:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 8.0.7. in /storage/ssd4/678/18965678/laravel/vendor/composer/platform_check.php on line 24
This basically means that the lock file references dependencies that - if they would be installed - would be incompatible with the PHP version Composer has detected on the system where composer install
is running.
Compare with the error message: A PHP version equal or greater than 8.1.0
is required, but the detected PHP version is 8.0.7
which is below that version.
How to Solve?
The solution depends a bit on how they deal with both the pinned versions and the procurement and management of the platform.
Given the pinned versions in the lock file are leading, this requires the platform to match. This is often the case in a Composer based PHP project, so I suspect this is also their setup (the project ships with a defined dependency configuration in the composer.lock
file).
Then the solution is relatively simple: As the PHP version is too low, the system where you execute composer install
needs it upgraded to at least PHP version 8.1.0
. Commonly you'll take the latest in the 8.1.x
series.
After changing the system configuration you can run the Composer installation command again and Composers platform check should now pass successfully.
So much for the theory.
Locking for the Wrong Platform
My PHP version is already 8.1.6 sir, I don't know why the error said that. What I know is the hosting I use only supports up to PHP 8.0
The hosting is the system where you get the error. The my is the system where you create the lock file.
This now causes an issue. As you distribute the lock file, it is with the wrong platform. There are two ways to handle this, and both are about to align the PHP version between your system and the hosting system:
- Tell Composer which PHP version to use for the platform.
- Use the hosting PHP version on your system.
You can do 1., 2. and even both, they are not mutually exclusive.
Often most easy is 1. as it does not involve system configuration.
But 2. has more properties that can be beneficial for your PHP project development.
Tell Composer which PHP Version to use for the Platform
This is an option in your Composer project configuration. Configure the PHP platform version to the one of your hosting (8.0.7
):
$ composer config platform.php 8.0.7
(the command does not produce any output when successful)
Afterwards you have to update the project dependencies as Composer is now using that configured PHP version 8.0.7
to resolve the dependencies:
$ composer --no-plugins update --no-scripts
Loading composer repositories with package information
...
Updating dependencies
...
Generating autoload files
This updates the lock file while taking care that only dependency versions that are compatible with that PHP version are being required.
Now commit the lock file and publish the project with it.
$ composer validate --no-check-publish \
&& git add composer.json composer.lock \
&& git commit -m "configure, update and lock dependencies" \
&& git push hosting
...
Use the Hosting PHP Version on your System
You should normally develop the PHP project with the same PHP Version that you use on the system(s) where it is run. This helps to prevent issues when the PHP runtime configuration deviates, like a different PHP version as in your case.
Consult your teams development documentation on how to configure the PHP runtime on a development box. If there is no team and also the project documentation does not cover it, consult your system operations' or operation systems' manual if you there is no professional system administration at hand you can consult.
This is normally done with the systems package manager. For example I have a couple of PHP versions installed on my system. Within each project development environment then, I specify which PHP version to use and develop with it.