问题
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?)
回答1:
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, runvagrant 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 fileto
was prefixed with/home/vagrant
- Run
ls
andLaravelProjects
should be visible. Contained withinLaravelProjects
should be yourtodo
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.
回答2:
In your Homestead.yaml
folders:
- map: ~/Code
to: /home/vagrant/Code
According to the documentation
来源:https://stackoverflow.com/questions/41041625/how-to-create-a-shared-folder-between-homestead-and-my-local-machine