Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0"

Viewed 252863

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.

23 Answers

Follow this trick

  1. add this line in config object of composer.json file

    "platform-check": false

  2. run php artisan config:cache

  3. then run composer dump-autoload in terminal

Project or global composer.json file:

{
    "config": {

        "platform-check": false
    }
}

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.

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"
     }
}

Actually, this was the only solution that worked for me:

composer global update
composer dump-autoload

This worked for me:

sudo a2dismod php7.2
sudo a2enmod php7.4
sudo service apache2 restart

Adjust php7.2 to your current module.

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.

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

Open cPanel and type multiphp Manager. After that, select your desired domain and at the top right corner, change the PHP version to 7.3 or whatever you would like. Give it some time and your site will be up and running!

See screenshot

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.

Linux users

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.

Windows users

  1. 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.

  2. 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.

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.

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.

The same problem downgrading from PHP 8.0 to 7.2 needed to run an older project.

How I have fixed my issue:

  • Remove the broken dependency (installed previously with PHP 8)
  • Unlink the newest PHP version then link the older PHP version (I have used brew CLI to link/unlink $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)
  • Then reinstall the dependency

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.

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

  • XAMPP was installed multiple times (without uninstalling the previous).
  • I uninstalled the one being shown in programs list.
  • restarted the PC.
  • then deleted all the directories of XAMPP.
  • restarted the PC.
  • installed XAMPP again.
  • -- that’s all.

For cPanel users here is the latest selection, and this is latest for 2022 option

enter image description here

enter image description here

I encountered this issue on Aapanel on my VPS. I already had the latest version of PHP (PHP 8.1) but still, the error did not go every time I tried to run a composer command. I had many versions of PHP running, I tried all the suggested options but none worked. So I thought that maybe composer was seeing the wrong version of PHP and decided to uninstall lower versions(7.2,7.4) and that solved the error!

Error for me was :

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0"

Solution: 1. enter image description here

2.

enter image description here

it depends on how you check your PHP version, while there are different SAPIs in PHP, checking the version in Apache2 SAPI using phpinfo() is totally different from checking it from your terminal using php -v.

Usually, when you install multiple versions, the OS does not override the old versions, for example, if you have PHP7.4, then when you install PHP7.3 you will have the two versions installed. however, your web server is not capable to manage the two versions at the same time.

In your case, all that you need to fix this issue is to make sure that you are using the right SAPI in the right place.

in your terminal check the version by using php -v, make sure that you are using the right version php7.3 in this case. and in your web server use phpinfo() to detect the current version, if it is not php7.3 you will need to enable it by the following command:

a2enmod php7.3

and if the error you are getting is in installing packages, you can install your package directly using the right bin

php7.3 /usr/local/bin/composer require package_name

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!

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)

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

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
Related