Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Leff7's avatar
Level 4

Vagrant\Homestead - setting up multiple php versions

I have installed virtual box on my machine few months ago, and I have read that it is possible to set the PHP version per project in Homestead.yaml file, here in the laravel docs. In the warning there it says

this feature is only compatible with Nginx

I thought we are running Nginx on Homestead? How can I also check if I am having the latest homestad version since this is possible only since Homestead 6 release. I have with homestead-v but that gave me an error that the homestead command was not found.

0 likes
11 replies
ejdelmonico's avatar

@leff7 First destroy your vm with vagrant and then go to your Homestead directory and run git fetch and git checkout v7.0.1. The, open Homestead.yaml and declare the php version for each project listed and if you want MariaDB instead of MySQL. Then run vagrant up.

sites:
    - map: homestead.test
      to: /home/vagrant/code/Laravel/public
      php: "7.2"
2 likes
ederson's avatar

sorry to hijack but i have the same problem and it is driving me nuts!

i need to use php 7.1 instead of 7.2

so i destroy the vm declare the php version for the project : php: "7.1" git fetch


remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/laravel/homestead
   1be508a..241c926  master     -> origin/master

git checkout v7.0.1

HEAD is now at 0d0082e... ? ? Tagging v7.0.1 (#750)
M       composer.lock
M       resources/Homestead.yaml

and the vagrant up....

php -v keeps saying 7.2 !!!

i am obviously doing something wrong here but i have absolutely no idea what......

Cronix's avatar

@ederson php -v (which you run from the command line) tells the version of php-cli, which is not necessarily the same version of php that the website is running on. It may be that specifying the php version in homestead.yaml sets it for the webserver, but not the cli.

If you make a route like /test and then browse to it...

Route::get('test', function() {
    phpinfo();
});

What version of php does it show running on the webserver?

3 likes
ederson's avatar

Thanks cronix..

I realised this a bit after posting here .... I knew a was missing something obvious

danielme's avatar

I got here searching for how to use different php-cli running Laravel commands. So in case anyone else was wondering that: there seems to be shortcuts for the cli-binaries allready in Homestead. Just replace 'php' with 'php7.1' etc...

php7.1 -v
PHP 7.1.13-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jan  5 2018 13:26:45) ( NTS )

convenient!

aimfeld's avatar

You may change the php cli version (e.g. to 7.1) like this:

sudo ln -sf /usr/bin/php7.1 /usr/bin/php

Change the php cli version back to default:

sudo ln -sf /etc/alternatives/php /usr/bin/php

So you can temporarily change the php cli version e.g. for older deployment cli scripts.

3 likes
yabasha's avatar

To change default php-cli default version run the following command:

sudo update-alternatives --config php

and then choose from the list of php versions the one you want

12 likes
Faran's avatar

Run the command in terminal after entering vagrant using vagrant ssh

1 like

Please or to participate in this conversation.