I have uploaded my Laravel project to AWS hosting when I go to the IP address of EC2 instance it give me this error:
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0".
I check the PHP version and the current version 7.3. I don’t know what I actually need to do. First the version was 7.4, and then I downgraded it to 7.3.
Problem:
Your Composer checks the platform requirements (PHP version and loaded extensions) when the autoloader is loaded. If you run the application which does not meet the platform requirements, the application will exit with a message similar to this:
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0".
Solution:
You could use the easiest way: add --ignore-platform-reqs option to composer install/composer update to ignore all platform requirements.
Project or global composer.json file:
{
"config": {
"platform-check": false
}
}
Follow this trick
add this line in config object of composer.json file
"platform-check": false
run php artisan config:cache
then run composer dump-autoload in terminal
Ignoring is not the right option. You have to upgrade your PHP version. Take into account that by now, we already have PHP 8, so with version 7.2 you are far behind.
Depending on your distributions, if you are using a Debian derivative like Ubuntu, use this link guide: Upgrade PHP version to PHP 7.4 on Ubuntu or just google for it and all will be fine.
If you are using Windows, with Laragon, so all you have to do is download the PHP version that you want from https://www.php.net/downloads.php. Unzip the folder to c:/laragon/bin/php folder and then using Laragon GUI select another version in Menu/php.
If you wish to upgrade the global Windows PHP version, you can use the Web Platform Installer. This for me was one the easiest way of doing it on Windows. For more information follow Install and Configure PHP.
Actually, this was the only solution that worked for me:
composer global update
composer dump-autoload
First of all, read the warning! It says do not run Composer as root! Secondly, you're probably using XAMPP on your local which has the required PHP libraries as default.
But in your server you're missing ext-dom. php-xml has all the related packages you need. So, you can install it by running:
sudo apt-get update
sudo apt install php-xml
Most likely you are missing mbstring too. If you get the error, install this package as well with:
sudo apt-get install php-mbstring
Then run:
composer update
Then run: to reload you Apache server:
sudo systemctl reload apache2
If you're like me who had to downgrade the PHP version on your machine (Mac) due to a specific reason and when you run valet use php --force, you see the Composer global dependencies require PHP v7.3.0 or higher, then you're in the right place. You can comment out the following three lines temporarily and that shall fix the issue for you when running valet use php --force again.
Path: ~/.composer/vendor/composer/platform_check.php
if (!(PHP_VERSION_ID >= 70300)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.3.0". You are running ' . PHP_VERSION . '.';
}
Note: don't forget to uncomment the relevant three lines after you switch to the latest version of PHP.
This worked for me:
sudo a2dismod php7.2
sudo a2enmod php7.4
sudo service apache2 restart
Adjust php7.2 to your current module.
Having used all of the previously-attempted solutions, I have found that the one that works best is the following.
sudo apt-get update
sudo apt install php-xml
sudo apt-get install php-mbstring
sudo reboot
I managed to solve this problem by downloading a newer version of PHP that at the same time was compatible with the version of Apache installed from here!.
In the Laragon interface, I saw that the Apache version was "httpd 2.4.35 win64 VC15", so I looked for a version of the PHP that had this "vc15".
I downloaded the "php-7.4.19-Win32-vc15-x64" and selected it in my Laragon. In this link you can find how to replace the PHP version in Laragon here!
So, having struggled with this very problem,
PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.2.5". You are running 7.1.28
for several hours, and finding that none of the above suggestions worked, I finally discovered that -- at least on FreeBSD systems -- the PHP module required by Apache is not installed by the main PHP package (e.g., "php74-7.4.19"), but instead by a different, module-specific package with its own versioning (e.g., "mod_php71-7.1.28").
Executing php -v consults the php package; visiting phpinfo() consults the mod package.
The clue to this is to execute pkg info | grep php and examine the results to see which packages you have installed. Obviously you have to adjust the above for the packaging system your system uses.
Hashmat Waziri's answer is right, but if anybody want to use your platform's version, either Composer requires anything, he/she can set the code, depending on his/her system, into the composer.json file like:
"config": {
"platform": {
"php": "7.1.0"
}
}
The same problem downgrading from PHP 8.0 to 7.2 needed to run an older project.
How I have fixed my issue:
$brew link php@7.2, but I think you can use any PHP manager app to move to older version of PHP without any problem)This fixed my problem and allow me to switch between different version without further problems, only requirement is use:
composer global update
after switching PHP version to refresh global dependencies.
I have no clue about what caused the issue. Maybe something went funny during PHP version switch, but we weren't able to put our finger to the cause of the trouble.
P.S. Our problem was related to "laravel/install" package, uninstalling it required uninstall "laravel/valet" before, procedure isn't changed though, simply we have to reinstall both packages on PHP 7.2.
As mentioned in a comment under the original question, instead of just trying to hide the error or bypass it, It would be better to solve it completely to make sure the app performs the way it should. For that, we have to update the PHP version being used. I got this error in a cloud virtual_machine, so I had access to the terminal from where I installed the required version of PHP to the system.
After that, I switched the active version of PHP from the older version to the newer version.
To do this, I first ran,
sudo a2dismod php7.2
You will then see,
Module php7.2 disabled. To activate the new configuration, you need to run: systemctl restart apache2
As mentioned, run,
sudo systemctl restart apache2
Then run,
sudo a2enmod php8.0
This will enable the required version.Then run,
sudo systemctl restart apache2
A more detailed explanation is available here.
I would reinforce the instruction not to blatantly ignore warnings. Would you ignore a warning on an electric fence telling there was a risk of death if you touched it?
In my case I was trying to get an old application running, using PHP 7.2, so couldn't just change the PHP version.
My solution was fairly simple. Examine the composer.lock file to find which package requires the version of PHP reported in the warning. Find that package on packagist.org, look for a version of the package that matches your PHP version, and install it.
E.g.,
composer require <package>:<version>
You may need to go through this a number of times. In my case I had to install packages that were wanting PHP 7.4 and those wanting PHP 7.3 before my application was happy.
Those who are here after facing a similar issue on XAMPP (nothing to do with Laravel), I solved it by the following:
Error shown to me:
Composer detected issues in your platform: Your Composer dependencies require the following PHP extensions to be installed: mysqli, openssl
Please use --ignore-platform-reqs with your composer command.
--ignore-platform-reqs will ignore platform dependencies.
composer install --ignore-platform-reqs
or
composer update --ignore-platform-reqs
The best way I fixed mine was
Go to your xampp folder, look for php.ini
Changed this ;extension=mysqli to extension=mysqli And also change ;extension=openssl to extension=openssl
Restart your Apache and MySQL
Done (Working)