Homestead: Composer update fails with composer.json php version set to 7.1.*

Created on 8 Aug 2017  路  14Comments  路  Source: laravel/homestead

Versions

  • Vagrant: 1.9.1
  • Provider: Virtualbox 5.1.26r117224.
  • Homestead: 6.0.3

Host operating system

Fedora 26

Homestead.yaml

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Code
      to: /home/vagrant/Code

sites:
    - map: laravel.app
      to: /home/vagrant/Code/laravel/public

databases:
    - homestead

Expected behavior

$ composer update php
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
The compiled services file has been removed.

Actual behavior

$ composer update php
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php 7.1.* but your PHP version (5.6.4) does not satisfy that requirement.

Steps to reproduce

  1. Create a fresh homestead
  2. Inside Homestead run php --version to verify that PHP7.1 is installed and used from the CLI.
  3. Inside homestead run laravel new {project} to create a new Laravel project
  4. After installation has finished, edit the new project's "php": ">=5.6.4" entry to "php": "7.1.*",
  5. Run composer update php inside the project root.

Most helpful comment

Ahhh crap I see it now, its the

"platform": {
    "php": "5.6.4"
}

bit at the bottom. Sorry for wasting your time!

All 14 comments

PHP is just a version of PHP to run the project in requirement, not a dependency that must be updated in the /vendor folder like your packages.

The PHP version is managed in Homestead. Following the basic docs and you'll end up with your application running on PHP 7.1 by default.

@svpernova09 Yep that's right, the application does indeed run in PHP7.1 in the browser perfectly fine.

But as I want to use PHP7.1 language features, I want to be able to require php=7.1.* in my composer.json file so that other developers get an error when they try to install the application on a system with PHP7.0, or PHP5.6 or lower installed. That's what I'm trying to do, I'm definitely not trying to install PHP7.1 in my vendor folder 馃槅

The problem I have is, is that even though the application uses PHP7.1 fine in the browser, and running php --version shows that PHP7.1 is running via the CLI, changing the php requirement in composer.json and running composer update php (to update composer.lock) throws an exception because it says I'm running PHP5.6, when I've already verified that I'm not.

Does that make sense? I still think there is a bug here.

composer update php is never going to do what you think it does. The PHP version in your composer.json file is there JUST to limit what versions can run your project. If you want to change this, update the php setting in composer.json to ^7.1 and run composer update (without the php) and composer.lock should be updated accordingly.

@svpernova09 afraid its still an issue. I just changed "php": ">=5.6.4" to "php": "7.1.*" in my composer.json, then:

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php 7.1.* but your PHP version (5.6.4) does not satisfy that requirement.

So its still an issue when running composer update (as well as composer update php).

And additionally:

$ php --version
PHP 7.1.7-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jul  7 2017 09:41:45) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.7-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
    with blackfire v1.17.3~linux-x64-non_zts71, https://blackfire.io, by SensioLabs

Show me a complete output of vagrant destroy && vagrant up, also post your composer.json.

Also from INSIDE vagrant, run ls -alh /usr/bin/php and show the output.

@svpernova09 as requested:

[pbates@localhost Homestead]$ vagrant destroy
    homestead-7: Are you sure you want to destroy the 'homestead-7' VM? [y/N] y
==> homestead-7: Forcing shutdown of VM...
==> homestead-7: Destroying VM and associated drives...
==> homestead-7: Pruning invalid NFS exports. Administrator privileges will be required...
[sudo] password for pbates: 

[pbates@localhost Homestead]$ vagrant up
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Importing base box 'laravel/homestead'...
==> homestead-7: Matching MAC address for NAT networking...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
==> homestead-7: Setting the name of the VM: homestead-7
==> homestead-7: Clearing any previously set network interfaces...
==> homestead-7: Preparing network interfaces based on configuration...
    homestead-7: Adapter 1: nat
    homestead-7: Adapter 2: hostonly
==> homestead-7: Forwarding ports...
    homestead-7: 80 (guest) => 8000 (host) (adapter 1)
    homestead-7: 443 (guest) => 44300 (host) (adapter 1)
    homestead-7: 3306 (guest) => 33060 (host) (adapter 1)
    homestead-7: 5432 (guest) => 54320 (host) (adapter 1)
    homestead-7: 8025 (guest) => 8025 (host) (adapter 1)
    homestead-7: 27017 (guest) => 27017 (host) (adapter 1)
    homestead-7: 22 (guest) => 2222 (host) (adapter 1)
==> homestead-7: Running 'pre-boot' VM customizations...
==> homestead-7: Booting VM...
==> homestead-7: Waiting for machine to boot. This may take a few minutes...
    homestead-7: SSH address: 127.0.0.1:2222
    homestead-7: SSH username: vagrant
    homestead-7: SSH auth method: private key
    homestead-7: 
    homestead-7: Vagrant insecure key detected. Vagrant will automatically replace
    homestead-7: this with a newly generated keypair for better security.
    homestead-7: 
    homestead-7: Inserting generated public key within guest...
    homestead-7: Removing insecure key from the guest if it's present...
    homestead-7: Key inserted! Disconnecting and reconnecting using new SSH key...
==> homestead-7: Machine booted and ready!
==> homestead-7: Checking for guest additions in VM...
==> homestead-7: Setting hostname...
==> homestead-7: Configuring and enabling network interfaces...
==> homestead-7: Mounting shared folders...
    homestead-7: /vagrant => /home/pbates/Homestead
    homestead-7: /home/vagrant/Code => /home/pbates/Code
==> homestead-7: Bindfs seems to not be installed on the virtual machine, installing now
==> homestead-7: Creating bind mounts for selected devices
==> homestead-7: Creating bind mount from /home/vagrant/Code to /home/vagrant/Code
==> homestead-7: Running provisioner: file...
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: 
==> homestead-7: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeqVUmcTCqJn8oajZGop/dQYad4zHOum5HvhXVRVD3T4a6M5wdQWD4Nny5qn7P0b+6KbvFVKTD0d8YJA1Tg9D6I/BDKHUh7xYmg+I79znFXtOV/rhpDD+5pafkceAh1cuE4NUwknfuwSNhnrtKAaArr+sw0ohvSsKoKs2wExyIBmiQv6H164dgFyyEC7riMNtT8CqCfNdmdJtK73FH4S6jM6hAWGSDWItDeeFIbp/Y4SfSZKoQu3pZsLatxRXCdbubOYzO1EjiGfZDA9/9ZZyaJl6ufYSsELpXTFrBLGKeGlcogTWKvjCZWXWQp12nbWPSjrOHO5EldAnlMNnQKPA9 [email protected]
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: /tmp/vagrant-shell20170808-12285-16kitqs.sh
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Certificate: laravel.app
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Site: laravel.app
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Checking for old Schedule
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Restarting Nginx
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating MySQL Database: homestead
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Postgres Database: homestead
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Clear Variables
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Update Composer
==> homestead-7: Updating to version 1.5.0 (stable channel).
==> homestead-7:    
==> homestead-7: Downloading (connecting...)
==> homestead-7: 
==> homestead-7: Downloading (100%)
==> homestead-7:          
==> homestead-7: 
==> homestead-7: Use composer self-update --rollback to return to version 1.4.2
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: /tmp/vagrant-shell20170808-12285-14wqev0.sh

[pbates@localhost Homestead]$ vagrant ssh
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-81-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

130 packages can be updated.
10 updates are security updates.

vagrant@homestead:~$ php --version
PHP 7.1.7-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jul  7 2017 09:41:45) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.7-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
    with blackfire v1.17.3~linux-x64-non_zts71, https://blackfire.io, by SensioLabs

vagrant@homestead:~$ ls -alh /usr/bin/php
lrwxrwxrwx 1 root root 21 Jul 24 00:44 /usr/bin/php -> /etc/alternatives/php

vagrant@homestead:~$ cd Code/laravel
vagrant@homestead:~/Code/laravel$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php 7.1.* but your PHP version (5.6.4) does not satisfy that requirement.

composer.json is from a fresh Laravel 5.4 application using laravel new {project} except that I changed "php": ">=5.6.4" to "php": "7.1.*", everything else is the same.

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "7.1.*",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true,
        "platform": {
            "php": "5.6.4"
        }
    }
}

Ahhh crap I see it now, its the

"platform": {
    "php": "5.6.4"
}

bit at the bottom. Sorry for wasting your time!

Practical ( and maybe useful ) advise:
try ./composer instead of only composer and you will see.

(Thanks to my hosting company Skyberate)

I am unable to use this same solution in my standalone project. It gives me the same issue, even after I updated php in the config.platform :

Problem 1
- This package requires php 7.1.* but your PHP version (5.6.4) does not satisfy that requirement.

@fatemasagar

If you are using Cpanel or any other Panel to manage your server you should change your PHP version to 7.1 (or 7.2 with magento version 2.3)

Best regards

php version

Isn't updating the PHP version done internally from the project ?? @koopjesboom

@fatemasagar

It is don server side, if you don't know how to manage it ask your hosting provider.
You can use my image to explain.

Best regards

Hello here's my answer on stackoverflow.

https://stackoverflow.com/a/59462635/9019654

Welcome

Was this page helpful?
0 / 5 - 0 ratings