Homestead: How to upgrade PHP version
Homestead: How to upgrade PHP version
I installed a year ago Homestead with Laravel 5.5.
Now I want to upgrade to Laravel 5.6.
I upgraded Homestead as explained here with
vagrant box update
git pull origin master
This forced me also to upgrade my vagrant
to 2.1.2
.
vagrant
2.1.2
Now when I log in with
vagrant ssh
vagrant ssh
I cannot upgrade to Laravel 5.6, because when I run composer update
I get this warning:
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.3 but your PHP version (7.0.27; Package overridden via config.platform (actual: 7.1.7)) does not
satisfy that requirement. Problem 2
- laravel/framework v5.6.9 requires php ^7.1.3 -> your PHP version (7.1.7-1+ubuntu16.04.1+deb.sury.org+1) overridden by
"config.platform.php" version (7.0.27) does not satisfy that
requirement.
If I call php -v
in the vagrant machine I get
php -v
PHP 7.1.7-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jul 7 2017 09:41:45) ( NTS )
Which would be okay because Laravel only requires PHP 7.1.3
, but the upgrade gets stucks because composer claims I am using PHP 7.0.27
.
PHP 7.1.3
PHP 7.0.27
WHy is that and how can I fix it?
I even tried
sudo apt-get update
sudo apt-get upgrade
as suggested here but it still does not work. Some packages have been kept back on the upgrade:
The following packages have been kept back: libdrm-amdgpu1 libdrm2
libegl1-mesa libgbm1 libgd3 libgl1-mesa-dri libgl1-mesa-glx
libglapi-mesa libwayland-egl1-mesa mssql-tools open-vm-tools
php7.1-bcmath php7.1-cli php7.1-common php7.1-curl php7.1-dev
php7.1-fpm php7.1-gd php7.1-imap php7.1-intl php7.1-json
php7.1-mbstring php7.1-mysql php7.1-opcache php7.1-pgsql
php7.1-readline php7.1-soap php7.1-sqlite3 php7.1-xml php7.1-zip 0
upgraded, 0 newly installed, 0 to remove and 30 not upgraded.
1 Answer
1
The solution is actually part of your question. If we have a second look at the composer error:
Problem 1 - This package requires php >=7.1.3 but your PHP version (7.0.27; Package overridden via config.platform [...]
This means you do have something like the following in your composer.json
, which you need to change or remove prior to the update:
composer.json
"config": {
"platform": {
"php": "7.0.7"
},
"preferred-install": "dist",
"optimize-autoloader": true
}
You can change it to the actual platform version or remove it at all. It is used to emulate an environment, which can be handy if you want to check if you could for example run composer install
on your server when it has another PHP version than your development machine.
composer install
"platform": { "php": "7.0.7" },
I added an explanation in my answer, which might give you an idea what it does. So yes, go ahead and remove it or set it to your new PHP version.
– Namoshek
Jun 29 at 11:26
This is the answer to the question but please note that that platform variable might have been intentional. Maybe your deployment server only has php 7.0.7, so you upgrading your local php version is bound to create the exact same errors later on when you deploy again.
– Loek
Jun 29 at 11:43
@Loek Well, then they shouldn't update to Laravel 5.6. :)
– Namoshek
Jun 29 at 11:46
Haha yep, but I've seen so many people make "mistakes" like this, I just thought to point it out.
– Loek
Jun 29 at 11:47
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Just remove
"platform": { "php": "7.0.7" },
?– Adam
Jun 29 at 11:26