在 PHP5.6 和 PHP7 项目中使用 Laravel Homestead
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41804727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Laravel Homestead for PHP5.6 and PHP7 projects
提问by Bart Bergmans
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.
在办公室,我们使用 Homestead 作为我们的本地开发环境。到目前为止,我们所有的项目都是用 PHP5.6 制作的。现在我们有一个新项目,我们将使用 PHP7。我无法在我当前的 PHP5.6 homestead 机器上运行 PHP7。如何实现运行 PHP5.6 和 PHP7 项目?它们不必同时运行,所以我如果可以更改它Homestead.yaml
以使用较新的版本,那就没问题了。
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.
我已经尝试过的是运行vagrant box add laravel/homestead --box-version 1.0.1
. 这添加了 1.0.1 框,但是当我添加version: 1.0.1
到我的Homestead.yaml
并开始 vagrant 时,PHP 版本仍然是 5.6。
回答by Laurence
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.
如果您运行 Homestead v6 或更高版本 - 默认情况下您会自动安装多个 PHP 版本。
In your Homestead.yaml
file you can set the version:
在您的Homestead.yaml
文件中,您可以设置版本:
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:
此外,您可以通过 CLI 使用任何受支持的 PHP 版本:
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
查看 Laravel 文档了解更多信息:https://laravel.com/docs/5.4/homestead#multiple-php-versions
回答by Ralf Lütke
The latest Laravel-Version with Homestead including PHP 5.6 is Laravel 5.6. See https://laravel.com/docs/5.6/homesteadfor details and installation instructions.
Use the following commands during installation to get this Homestead-Vagrant-Box:
Homestead 的最新 Laravel 版本包括 PHP 5.6 是 Laravel 5.6。有关详细信息和安装说明,请参阅https://laravel.com/docs/5.6/homestead。
在安装过程中使用以下命令来获取这个 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)
此 Homestead 版本支持 PHP 5.6 到 7.3。
(更多德语详细信息:https: //blog.dmr-solutions.com/blog/homestead-vagrant-box-mit-php-56)
回答by Bart Bergmans
Found a solution! I followed thistutorial. 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:
找到了解决办法!我跟着这个教程。我可以运行 PHP 5.6 和 PHP 7 Homestead。我唯一要做的事情(我已经配置了 PHP 5.6 homestead)是:
- 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
- Go into this directory and run
bash init.sh
and answer no to all questions. - 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)
- 通过运行在 Homestead-7 文件夹(或其他名称)中克隆最新的 homestead 版本
git clone https://github.com/laravel/homestead.git ~/Homestead-7
- 进入这个目录并运行
bash init.sh
并回答所有问题。 - 就是这样!您可能需要升级您的流浪者(我的太旧了),但只需在https://www.vagrantup.com/downloads.html上下载最新版本即可轻松完成(不要忘记
vagrant provision
在 Homestead-7 中运行)
回答by Apit John Ismail
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.
将 php5.6 添加到 Homestead.yml 后,您不能简单地执行“vagrant up --provision”。不起作用。您必须通过运行命令“vagrant destroy”来实际销毁虚拟机并重新创建虚拟机。
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.
因此,在销毁虚拟机之前,最好备份其中的每个数据库。我通过将所有 sql 转储到 Code 文件夹中来做到这一点。稍后在我运行“vagrant up”命令后,我可以简单地通过 ssh 连接到我的虚拟机并转到 mysql 并再次在 mysql 命令行中运行“source dump.sql”。