25

I am getting this error with Laravel 9, I have PHP 8.1.7 installed

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

I can see other have asked the question, bit non of the solutions seem to be working

Mendy Kahan
  • 393
  • 1
  • 3
  • 6
  • 5
    It looks like you have multiple PHP versions. Type `php -v` in the same terminal where you use composer. – Markus Zeller Jul 03 '22 at 12:52
  • 1
    /usr/local/bin# php -v PHP 8.1.7 (cli) (built: Jun 25 2022 08:12:59) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.7, Copyright (c) Zend Technologies with Zend OPcache v8.1.7, Copyright (c), by Zend Technologies uninstalled and reinstalled Laravel (laravel 9) still same issue – Mendy Kahan Jul 04 '22 at 14:52
  • 1
    When is this issue occuring while `composer install`? – Sujith Sandeep Jul 07 '22 at 06:52
  • Can you elaborate more about your environment? How are you accessing composer? – Sibidharan Nov 08 '22 at 21:45
  • 1
    You can comment checking php version in vendor/composer/ platform-check file and replace it by a False condition like if (1==2) – Jamal Azizbeigi Apr 14 '23 at 06:46

15 Answers15

45

TIPS

Add this lines in composer.json file:

{
    "config": {

        "platform-check": false
    }
}

Or set the version:

{
    "config": {

        "platform": {
            "php": "7.1.0"
        }
    }
}

And run composer dump-autoload

Cesar Devesa
  • 990
  • 6
  • 14
16

If you install composer globally, just run composer global update. It will solve your problem.

enter image description here

Imtiaz Epu
  • 171
  • 1
  • 5
  • Running Valet Windows commands on php 8.1 works, but not 7.4 because a dependency of valet's dependency required 8.1. This answer solved my problem. – Studocwho May 09 '23 at 17:26
13

I had the same problem and it was because I configured a version of PHP 8.1 on the command-line while I kept the PHP module at 8.0.

So PHP_VERSION_ID gave me 80020, while php -v gave me 8.1.7.

It reminded me to reconfigure the PHP Module to PHP version 8.1:

sudo a2dismod php8.0

sudo a2enmod php8.1

sudo systemctl restart apache2

And then everything worked like intended.

Reference:

hakre
  • 193,403
  • 52
  • 435
  • 836
eiriel
  • 169
  • 3
  • I just post this [link](https://tecadmin.net/how-to-install-php-on-debian-11/) additionally. I had to install php 8.1 on debian server and I chose it with $sudo update-alternatives --config php. Then everything worked properly – Taranis Sep 18 '22 at 15:39
7

Don't change any thing in your application. In your shared hosting, go to cPanel and find/search for Multi PHP Manager. Select your domain or sub domain (whatever you are working with), from the dropdown list select PHP 8.1 and apply.

enter image description here

Now find/search PHP Selector and for Current PHP Version select 8.1.

enter image description here

in the same window go to Extensions and enable pdo_mysql.

enter image description here

You are good to go.

Khalil
  • 187
  • 2
  • 10
5

If @eril answer did not help you by disabling old PHP version

sudo a2dismod php8.0
sudo a2enmod php8.1
sudo systemctl restart apache2

use composer -vvv about to check that composer use correct version of PHP

composer -vvv about 2>&1 | grep "PHP"

if composer about already shows a correct version of PHP,then check to see the real PHP binary path that composer is using by putting PHP_BINARY inside vendor/composer/platform_check.php like this:

if (!(PHP_VERSION_ID >= 80100)) {
    $issues[] = 'You are running ' . PHP_VERSION . ' located at: ' . PHP_BINARY;
}

in my case, an old version of php-fpm was enabled.

a2disconf php8.0-fpm 
a2enconf php8.1-fpm 
sudo systemctl restart apache2
osyan
  • 1,784
  • 2
  • 25
  • 54
4

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". I faced the same problem. Just go to Cpanel. Then PHP Selector and finally, change PHP version enter image description here

ismaildev.com
  • 73
  • 1
  • 1
  • 6
2
Your Composer dependencies require a PHP version ">= 8.1.0"

I had this same issue while I downgraded my php to v7.4 from 8.1. I somehow messed up with php7.4-fpm mod. However, when I again tried to upgrade my php v8.1 composer started to complain about that error. I simply removed my both php versions that's 7.4 and 8.1 and re-installed only 8.1, which fixed my issue.

To remove, here are the steps I followed....

sudo apt-get purge php8.*
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php8.1

and then finally,

sudo service apache2 restart 
Humayun
  • 976
  • 7
  • 13
2

Open your composer.json and check where the 'require' block says 'php'. It has an expression that can put a constraint on the PHP version or version range that is allowed for all of your projects' dependencies.

A good value would be to use the one below. Change it and run composer update afterwards.

    "require": {
        "php": "^8.0|^8.1",

Contrary to the composer.json which laravel 9 ships with:

    "require": {
        "php": "^8.0.2",

(see laravel 9 composer.json in the official repository: https://github.com/laravel/framework/blob/9.x/composer.json)

Johan van den Broek
  • 384
  • 2
  • 5
  • 18
2

in my case everything is fine

  • composer.json is fine
  • php 8.1 is installed
  • I am using nginx I restart nginx but I found that my configuration is wrong it looks like this
location ~ \.php$ {
    fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
}

so the correct configuration is

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}

Hope this will help someone

Raj Omer Mustafa
  • 81
  • 1
  • 1
  • 5
0

If you are simply using git to version your Composer dependencies for a deployment, consider the --ignore-platform-reqs flag.

  • For more info, see Options at https://getcomposer.org/doc/03-cli.md#install-i

    composer update --dry-run --ignore-platform-reqs
    

    --ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.

Etienne Jacquot
  • 176
  • 1
  • 9
0

If you are operating on nginx server, It's likely the php-fpm8.1 is not active.

Try to:

sudo systemctl status php-fpm8.1.service

Depends on the status of the php-fpm version, you can act, and if it's stopped, you may want to do the following:

sudo systemctl enable php-fpm8.1.service
sudo systemctl start php-fpm8.1.service

Then double-check the status, and if it's active. You're good to go.

Note: This applies to any php-fpm version, not just 8.1.

Hope this help!

Oussama
  • 165
  • 12
0

if you use XAMPP, check that the PHP version of your XAMPP is the correct one (the same one you have on your computer). Otherwise, download and install the correct version of XAMPP

Cedriga
  • 3,860
  • 2
  • 28
  • 21
0

If you are in the process of upgrading Laravel versions and you switch to the version which requires PHP8 (8 or 9 cant remember) And you also switch PHP versions, you need to restart your

php artisan serve
alex toader
  • 2,300
  • 1
  • 17
  • 20
0

I had the exact issue.

  • I added the line phpversion() and found that the version was different from what was set for my apache.

  • I enabled the php8.1-fpm with this command:

    sudo a2enconf php8.1-fpm
    
  • After restarting Apache I got it working.

Eugene Kaurov
  • 2,356
  • 28
  • 39
erez taiar
  • 56
  • 3
-2

It's just until I find how to solve it but it's working So that's what i've done :

  • download php 8.1.9 (nts)
  • extract it in bin/php/ (i use Laragon)
  • move php 7.14.19 in a new folder(just for preventing)
  • and rename my php 8 folder to php 7 folder name
  • it's still working

Just find the php folder of your server

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 05 '22 at 02:52
  • just download the last Laragon then – ANTMANS Amir Apr 27 '23 at 15:20