lonestar
lonestar

Reputation: 387

Composer does not detect php7 instead it uses 5.6. How can I set the CLI to use php7

Here when I execute php -v , it says it has php7

enter image description here

but when I try to execute composer update

the response it

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php >=7.0.0 but your PHP version (5.6.33) does not satisfy that requirement.

How can I fix this? NOTE : I'm not allowed to uninstall previous version of php

Here is the composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "~3.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/passport": "^v1",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~6.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "files": [
            "app/Helpers/misc.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

I already tried

composer update --ignore-platform-reqs

but I still I get another error, which is again related to the above problem.

Upvotes: 4

Views: 10287

Answers (6)

justice
justice

Reputation: 85

i had same issue and solved it by changing path under system variables.

  • right click on my computer and click properties
  • click advanced system settings on the left side menu
  • make sure the advance tap menu is selected
  • click on environment variables (buttom right)
  • click on path under system variables panel
  • click on edit
  • locate php installed path (eg. C:\wamp64\bin\php\php5.x.x)
  • click edit and rename to your disired php version (eg. C:\wamp64\bin\php\php7.3.5)
  • click ok to save

Upvotes: 2

Krzysztof Dryja
Krzysztof Dryja

Reputation: 21

I use phpbrew for multi PHP versions. In my case this command fixed the issue with composer using wrong PHP version:

phpbrew app get composer

Upvotes: 0

Veerendra
Veerendra

Reputation: 2622

As stated in the question you already have both the versions of PHP on your system, As Laravel uses the cli version you need to enable 7.X and disable 5.X.

You can achieve that by below commands

$ sudo a2dismod php5.6 // disable the loaded version
$ sudo a2enmod php7.0 // enable the desired version
$ sudo service apache2 restart // restart apache to get it in action

For More information You can install different version of PHP using the below commands

For Apache

$ sudo apt install php5.6   [PHP 5.6]
$ sudo apt install php7.0   [PHP 7.0]
$ sudo apt install php7.1   [PHP 7.1]

For Ngix

$ sudo apt install php5.6-fpm   [PHP 5.6]
$ sudo apt install php7.0-fpm   [PHP 7.0]
$ sudo apt install php7.1-fpm   [PHP 7.1]

To install any PHP modules, simply specify the PHP version and use the auto-completion functionality to view all modules as follows.

------------ press Tab key for auto-completion ------------ 
$ sudo apt install php5.6 
$ sudo apt install php7.0 
$ sudo apt install php7.1 

Now you can install most required PHP modules as per your requirements.

------------ Install PHP Modules ------------
$ sudo apt install php5.6-cli php5.6-xml php5.6-mysql 
$ sudo apt install php7.0-cli php7.0-xml php7.0-mysql 
$ sudo apt install php7.1-cli php7.1-xml php7.1-mysql 

Upvotes: 5

Nico Haase
Nico Haase

Reputation: 12092

If you want to run composer with a different PHP version, try calling it using php $(which composer) update. You can exchange the path to the PHP cli now freely

Upvotes: 1

Madhu Nair
Madhu Nair

Reputation: 436

Install via this sudo apt install php7.1 php7.1-fpm and recheck again and post the result.

Upvotes: 0

Armin
Armin

Reputation: 15938

Check where your composer executable is located (using which) and check the first line (shebang). I guess this still points to old php version.

Upvotes: 0

Related Questions