了解 Laravel 中的 Homestead yaml 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29143680/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:10:01  来源:igfitidea点击:

Understanding the Homestead yaml file in Laravel

laravelvagrantyamlvirtualboxhomestead

提问by fs_tigre

Can someone explain the Homestead.yaml file in details. Not fully understanding its contents is bothering me.

有人可以详细解释一下 Homestead.yaml 文件。不完全理解它的内容让我很困扰。

Here is the complete Homestead yaml file:

这是完整的 Homestead yaml 文件:

ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Code
      to: /home/vagrant/Code

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

databases:
    - homestead

variables:
    - key: APP_ENV
      value: local

And here is what I understand about its content, correct me if I'm wrong and of course add comments.

这是我对其内容的理解,如果我错了,请纠正我,当然还要添加评论。

authorize:~/.ssh/id_rsa.pub
A directory in your local machine where you store the public .ssh file. This folder can be any folder in your local machine, right?

keys:- ~/.ssh/id_rsa
A directory in your local machine where you store the local .ssh file. This folder can be any folder in your local machine, right?

folders:
- map: ~/Code
to: /home/vagrant/Code

  • -map: A directory in your local machine where you store all of your porjects. This folder can be any folder in your local machine, right?

  • to: I believe this is where your projects will be stored in the virtual machine, if this is correct, does the last folder needs to match the last folder in the local structure?

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

  • -map: I believe this is the url or domain you will be using to get to your site and it can be anything you want as long as you add it to your localhost file, correct?

  • to: I'm not sure what this is...

databases:
- homestead
A databese called homestead will be created automatically, correct?

授权:~/.ssh/id_rsa.pub
本地计算机中存储公共 .ssh 文件的目录。这个文件夹可以是你本地机器上的任何文件夹,对吧?

密钥:- ~/.ssh/id_rsa
本地计算机中存储本地 .ssh 文件的目录。这个文件夹可以是你本地机器上的任何文件夹,对吧?

文件夹:
- 映射:~/Code
到:/home/vagrant/Code

  • -map:本地机器中存储所有项目的目录。这个文件夹可以是你本地机器上的任何文件夹,对吧?

  • to:我相信这是您的项目将存储在虚拟机中的位置,如果这是正确的,最后一个文件夹是否需要与本地结构中的最后一个文件夹匹配?

站点:
- 地图:homestead.app
到:/home/vagrant/Code/Laravel/public

  • -map:我相信这是您将用于访问您的站点的 url 或域,只要您将其添加到 localhost 文件中,它就可以是您想要的任何内容,对吗?

  • to:我不确定这是什么...

数据库:
- homestead
一个名为 homestead 的数据库将自动创建,对吗?

Thanks

谢谢

回答by Borjante

authorize: ~/.ssh/id_rsa.pub A directory in your local machine where you store the public .ssh file. This folder can be any folder in your local machine, right? Yes

授权:~/.ssh/id_rsa.pub 本地计算机中存储公共 .ssh 文件的目录。这个文件夹可以是你本地机器上的任何文件夹,对吧?是的

keys: - ~/.ssh/id_rsa A directory in your local machine where you store the local .ssh file. This folder can be any folder in your local machine, right? Yes

密钥: - ~/.ssh/id_rsa 本地计算机中存储本地 .ssh 文件的目录。这个文件夹可以是你本地机器上的任何文件夹,对吧?是的

Homestead.yaml uses lots of defaults, this way when creating a new .ssh key you do not need to touch anything

Homestead.yaml 使用了很多默认值,这样在创建新的 .ssh 密钥时你不需要接触任何东西

folders: - map: ~/Code to: /home/vagrant/Code

文件夹: - 映射:~/Code 到:/home/vagrant/Code

-map: A directory in your local machine where you store all of your porjects. This folder can be any folder in your local machine, right? Yes to: I believe this is where your projects will be stored in the virtual machine, if this is correct, does the last folder needs to match the last folder in the local structure? No there isno need to, you just specify a route in your virtual machine and it will be filled with all files in the -map: folder

-map:本地机器中存储所有项目的目录。这个文件夹可以是你本地机器上的任何文件夹,对吧?Yes to:我相信这是您的项目将存储在虚拟机中的位置,如果这是正确的,最后一个文件夹是否需要与本地结构中的最后一个文件夹匹配?不,没有必要,您只需在虚拟机中指定一个路由,它将填充 -map: 文件夹中的所有文件

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

站点: - 地图:homestead.app 到:/home/vagrant/Code/Laravel/public

-map: I believe this is the url or domain you will be using to get to your site and it can be anything you want as long as you add it to your localhost file, correct? to: I'm not sure what this is...

-map:我相信这是您将用于访问您的站点的 url 或域,只要您将其添加到 localhost 文件中,它就可以是您想要的任何内容,对吗?to:我不确定这是什么...

This two lines are configuring something like a virtualhost, i'm not sure how it really works internally, but basically you map one folder (to) to one domain (map), this will create a new virtualhost so that you can access you website by typing: homestead.app in you local machine browser. Remember that you need to edit your hosts file, either /etc/hosts or /windows/system32/drivers/etc/hosts and add a new line something like:

这两行正在配置类似虚拟主机的东西,我不确定它在内部是如何真正工作的,但基本上您将一个文件夹(到)映射到一个域(映射),这将创建一个新的虚拟主机,以便您可以访问您的网站通过在本地机器浏览器中键入:homestead.app。请记住,您需要编辑您的主机文件,/etc/hosts 或 /windows/system32/drivers/etc/hosts 并添加一个新行,如下所示:

192.168.10.10 homestead.app

192.168.10.10 homestead.app

databases: - homestead Not sure about this one, i will take a look at it but it seems to me that you are right, just define a new name and omestead will create DB for you.

数据库:- homestead 不确定这个,我会看看它,但在我看来你是对的,只需定义一个新名称,omestead 就会为你创建数据库。

Hope this helps

希望这可以帮助

回答by BenjaminCao

databases: - homestead A databese called homestead will be created automatically, correct?

数据库: - homestead 一个名为 homestead 的数据库将自动创建,对吗?

Yes. And if you want to create more databases, you can just add the database name bellow the - homestead, and then run the command homestead provision, you will see the database is created.

是的。如果你想创建更多的数据库,你可以在下面添加数据库名称- homestead,然后运行命令homestead provision,你会看到数据库被创建。

NOTICEthe provision is harmful, for it will reset the database, and the data in you database will be removed as same as the tables.

注意该规定是有害的,因为它会重置数据库,并且您数据库中的数据将与表一样被删除。

回答by Matt Setter

You can also add an optionselement to the map/toelements in the folderelement, as in the example below, and to that, specify a range of options, which are documented in the Vagrant documentation.

您还可以optionsmap/to元素中的folder元素添加一个元素,如下例所示,并为此指定一系列选项,这些选项记录在 Vagrant 文档中

- map: ~/Workspace/my/mapped/directory
  to: /home/vagrant/my/directory
  options: 
      owner: "www-data"
      group: "www-data"
      mount_options: ["dmode=0770,fmode=774"]

回答by Meta Pakistani

Though I am late to answer but I recently installed Homestead and Homestead.YAML was hard to understand as official documentation is lacking. Stumbled upon a very good article but its too long to copy here so I will just provide a link to it, Hope it may help newbies.

虽然我回答晚了,但我最近安装了 Homestead 和 Homestead.YAML 很难理解,因为缺乏官方文档。偶然发现了一篇很好的文章,但复制到这里太长了,所以我只提供一个链接,希望它可以帮助新手。

https://abbasharoon.me/homestead-yaml-explained-a-z/

https://abbasharoon.me/homestead-yaml-explained-az/