Hussein Barada
Hussein Barada

Reputation: 117

How to create a shared folder between Homestead and my local machine

I'm a computer science graduate. I have just started an internship at a company where they use Laravel. My first task was to install Homestead. I did that. My second task is to create a shared folder between Homestead and my local machine (I have a macbook pro). I had a quick look on Laravel documentation but I didn't find any article related directly to this subject. Can somebody help me on this subject? (How can I create a shared folder between Homestead and my local machine?)

Upvotes: 2

Views: 3458

Answers (2)

kagundajm
kagundajm

Reputation: 1210

Don't worry you are not alone. This is one area that is confusing before one gets used in configuring shared folders on homestead.

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

sites: map: todo
       to: /home/vagrant/LaravelProjects/todo/public 

folders: map contains the root of your projects (the main folder containing your projects) on your local machine. Therefore using ~/LaravelProjects, it means all your projects are contained within the LaravelProjects folder in the home folder. You can make your root folder reside in any place and not necessarily the home folder.

folders: to refers to where the root folder LaravelProjects will be on the virtual machine. This will mirror the contents of your machines root folder.

sites:map will be the host name you will use to access your site. You can name it in any way you like.

sites:to is a reference of your document root or public folder that will be served by your web server. Therefore using /home/vagrant/LaravelProjects/todo/public, we are telling the web server to serve our app contained in the project todo. If the project files are contained in an inner folder like src then we would change it to /home/vagrant/LaravelProjects/todo/src/public.

In the chat I saw you asked how to edit the hosts file. You can use, use sudo open /etc/hosts

Update

Navigating to your shared folder

  • Change directory to your Homestead directory
  • Run the vagrant up command or if the VM is already running, run vagrant reload --provision
  • After the VM boots, connect to your VM using SSH vagrant ssh
  • Your prompt should change to vagrant@homestead:~$ which means you are now logged to the VM.
  • Run pwd and it should reflect /home/vagrant. This explains why in the Homestead.yaml file to was prefixed with /home/vagrant
  • Run ls and LaravelProjects should be visible. Contained within LaravelProjects should be your todo project.
  • Navigate to http://todo on your local machine and the browser should display the Laravel welcome screen signifying that everything is working as it should

You can now modify your project files on your local machine and the changes will be reflected on the VM and vice versa.

Upvotes: 7

jeanj
jeanj

Reputation: 2176

In your Homestead.yaml

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

According to the documentation

Upvotes: 3

Related Questions