如何得到一个 PHP-Laravel homestead vagrant box?

How to get a PHP-Laravel homestead vagrant box up?

我设置了一个 Virtualbox Ubuntu 并使用

在上面安装了 Vagrant
apt-get install vagrant

,没有别的。

根据这个:https://laravel.com/docs/5.8/homestead 我试过:

vagrant box add laravel/homestead

在这不起作用之后我使用了:

git clone https://github.com/laravel/homestead.git ~/Homestead

bash init.sh

这似乎工作正常。
所以我进入了我的代码(和一个 Vagrant 文件)所在的文件夹并尝试了

vagrant box add

(因为我没有找到 .box 文件或类似的东西...我需要一个吗??)

现在我得到错误:

Message: LoadError: cannot load such file -- /media/sf_contractManager/project1/backend/vendor/laravel/homestead/scripts/homestead.rb

我做错了什么?
据我了解 Vagrant 我应该从 Vagrant 盒子中得到一个完整的 environment/vm 或者?无需在 Vagrant 框内(或 Virtualbox 级别的外部)安装 php、mysql 等。 这样对吗? 我怎样才能调出 Vagrant 盒子?

So I went into the folder where my code (and a vagrant file) is and just tryed

vagrant box add

(because I don't find a .box file or something like this... do I need one??)

您不需要执行此操作,因为您已经在上一步中添加了一个框。 Box 正在 Vagrant/VirtualBox 级别处理,而不是您的项目 level/Laravel 级别。

层次结构:

VirtualBox
|-Vagrant
  |-Vagrant box (environment for your project)
  | |-your project
  | |-another project
  |-another Vagrant box
    |-another project

要调出内容,您必须转到 Homestead.yaml 所在的文件夹,然后 运行 vagrant up.

记得在vagrant up之前运行init.sh

No need to install php, mysql, etc. inside the vagrant box (or outside on virtualbox level). Is this correct?

You are right。但是您必须指定您需要在项目中使用的所有 "tools"。例如,某些 PHP/MySQL 版本。


比如新鲜的安装方式(18.04自己测试):

  1. 安装Vagrant and VirtualBox using the preferred way (apt-get or using an archive or something else). How to install from .deb file。只是我的意见:获取源存档并且手动安装。这样您就可以控制正在安装的软件的版本。而且你也会有一些经验。
  2. cd ~(转到主目录)
  3. vagrant box add laravel/homestead
  4. git clone https://github.com/laravel/homestead.git ~/Homestead
  5. cd ~/Homestead
  6. git checkout release
  7. bash init.sh./init.sh。确保 bash 脚本可执行。或者使用
sudo chmod +x init.sh

使其可执行。

  1. Configure Homestead.yaml with providers you need.
  2. vagrant up(在 Homestead 目录中)。
  3. 如果您的项目是一个网站,您可能希望从您的主机访问它。所以你必须用 192.168.10.10 mywebiste.local 左右编辑 /etc/hosts 文件。您可以在 homestead.yaml.
  4. 中找到 IP

您可以在 docs 中找到更多信息。