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.
18
Answers
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!
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:
Solution:
You could use the easiest way: add
--ignore-platform-reqs
option tocomposer install/composer update
to ignore all platform requirements.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 terminalIgnoring 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
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:
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 runningvalet use php --force
again.Path:
~/.composer/vendor/composer/platform_check.php
Note: don’t forget to uncomment the relevant three lines after you switch to the latest version of PHP.
This worked for me:
Adjust
php7.2
to your current module.So, having struggled with this very problem,
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:
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 [email protected]
, 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:
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,
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.
or
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!
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 usingphp -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 versionphp7.3
in this case. and in your web server usephpinfo()
to detect the current version, if it is not php7.3 you will need to enable it by the following command:and if the error you are getting is in installing packages, you can install your package directly using the right bin
so my solution to this issue was update php version on my mac
brew install php
.brew update
echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
then restart your terminal.
Add below code in composer.json
"config": {
and run command composer dump-autoload