简体   繁体   中英

Using Laravel Homestead for PHP5.6 and PHP7 projects

Here at the office we are using Homestead as our local development environment. All projects we had so far were made in PHP5.6. Now we have a new project and we are going to use PHP7. I can't run PHP7 in my current PHP5.6 homestead machine. How can I achieve to run PHP5.6 and PHP7 projects? They do not have to run at the same time, so I if it's possible to change the Homestead.yaml to use a newer version, that would be fine.

What I have tried already was to run vagrant box add laravel/homestead --box-version 1.0.1 . This added the 1.0.1 box but when I added version: 1.0.1 to my Homestead.yaml and started vagrant the PHP version was still on 5.6.

In case people find this post - the answer has changed.

If you run Homestead v6 or above - you automatically get multiple PHP versions installed by default.

In your Homestead.yaml file you can set the version:

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public
      php: "5.6"

In addition, you may use any of the supported PHP versions via the CLI:

php5.6 artisan list
php7.0 artisan list
php7.1 artisan list

Check the Laravel docs for more info: https://laravel.com/docs/5.4/homestead#multiple-php-versions

The latest Laravel-Version with Homestead including PHP 5.6 is Laravel 5.6. See https://laravel.com/docs/5.6/homestead for details and installation instructions.
Use the following commands during installation to get this Homestead-Vagrant-Box:

vagrant box add laravel/homestead --box-version 6.4.0
git clone https://github.com/laravel/homestead.git .
git checkout v7.20.0

This Homestead-Version supports PHP 5.6 to 7.3.
(More details in german: https://blog.dmr-solutions.com/blog/homestead-vagrant-box-mit-php-56 )

Found a solution! I followed this tutorial. I can run a PHP 5.6 and a PHP 7 Homestead. The only thing I had to do (I already have a PHP 5.6 homestead configured) was:

  1. Clone the latest homestead version in a Homestead-7 folder (or a different name) by running git clone https://github.com/laravel/homestead.git ~/Homestead-7
  2. Go into this directory and run bash init.sh and answer no to all questions.
  3. That's it! You might have to upgrade your vagrant (mine was too old) but that's easy to do by just downloading the latest version on https://www.vagrantup.com/downloads.html (Do not forget to run vagrant provision in Homestead-7)

I like to add to Laurence answer.

After adding php5.6 to Homestead.yml, you cannot simply do "vagrant up --provision". It will not work. You have to actually destroy the vm by running command "vagrant destroy" and recreate back the vm.

So before destroying the vm, better to backup every database you have in there. I do this by dumping all the sql in Code folder. Later after I run the command "vagrant up" I can simply ssh to my vm and go to mysql and run "source dump.sql" in mysql command line again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM