fsdolphin's avatar

Understanding the Homestead yaml file in Laravel

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

Here is the complete Homestead yaml file:

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?

Thanks

0 likes
1 reply
Chief's avatar
Chief
Best Answer
Level 1

You should watch/rewatch the Say Hello to Laravel Homestead 2.0 laracast.

Otherwise, ~/.ssh/id_rsa.pub and ~/.ssh/id_rsa are files in the host machine that contain the public and private SSH keys, respectively. Using the standard method of generating ssh keys ssh-keygen -t rsa -C "your_email@example.com" they will be stored in that directory and much simpler to use that way

In the folders section, yes, local projects are stored in the map: directory and accessible in homestead as defined in the to:, but you can also map folders for each project you want and they'll be accessed in homestead and vice versa. Though, most guys prefer using one major code directory.

folders:
- map: ~/Code
to: /home/vagrant/Code
- map: ~/MajorProject2   #other folder in your local machine
to: /home/vagrant/MajorProject2  #where folder will be accessible in homestead

Note: changes map in either location (homestead or local machine) will reflect either way.

In the sites section, you're correct about the map section. the to: property defines which homestead directory will be called when you visit your defined site e.g homestead.app. Just like the projects section, you can add other mappings for more sites

sites:
- map: homestead.app
to:/home/vagrant/Code/Laravel/public
- map: myothersite.app  #additional site
to: /home/vagrant/Code/MyOtherSite/public #the public dir myothersite.app site calls

At the database section, any new line added will enable automatic database creation of the same name.

Hope this helps, but you should watch the laracast. It explains this in more detail

1 like

Please or to participate in this conversation.