如何在Homestead和我的本地计算机之间创建共享文件夹 [英] How to create a shared folder between Homestead and my local machine
问题描述
我是计算机科学专业的毕业生.我刚刚在一家使用Laravel的公司开始实习.我的第一个任务是安装Homestead.我做到了 我的第二个任务是在Homestead和本地计算机(我有一个Macbook Pro)之间创建一个共享文件夹.我快速浏览了Laravel文档,但没有找到与该主题直接相关的文章. 有人可以帮助我解决这个问题吗? (如何在Homestead和本地计算机之间创建共享文件夹?)
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?)
推荐答案
别担心你并不孤单.这是一个让人迷惑的领域,用于在Homestead上配置共享文件夹之前.
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
包含本地计算机上项目的根目录(包含项目的主文件夹).因此,使用~/LaravelProjects
意味着您的所有项目都包含在主文件夹的 LaravelProjects 文件夹中.您可以将根文件夹放置在任何位置,而不必放置在主文件夹.
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
是指根文件夹LaravelProjects
在虚拟机上的位置.这将镜像您的计算机根文件夹的内容.
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
将是您用来访问站点的主机名.您可以使用任何喜欢的方式对其进行命名.
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
是将由Web服务器提供的文档根目录或公用文件夹的引用.因此,使用/home/vagrant/LaravelProjects/todo/public
,我们告诉Web服务器为项目todo
中包含的应用程序提供服务.如果项目文件包含在src
之类的内部文件夹中,那么我们将其更改为/home/vagrant/LaravelProjects/todo/src/public
.
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
.
在聊天中,我看到您询问如何编辑主机文件.您可以使用sudo open /etc/hosts
In the chat I saw you asked how to edit the hosts file. You can use, use sudo open /etc/hosts
更新
导航到共享文件夹
- 将目录更改为您的Homestead目录
- 运行
vagrant up
命令,或者如果VM已经在运行,请运行vagrant reload --provision
- 启动虚拟机后,使用SSH
vagrant ssh
连接到您的虚拟机
- 您的提示符应更改为
vagrant@homestead:~$
,这意味着您现在已登录到VM. - 运行
pwd
,它应反映/home/vagrant
.这解释了为什么在Homestead.yaml文件中to
以/home/vagrant
为前缀
- 运行
ls
和LaravelProjects
应该是可见的.包含在LaravelProjects
中的应该是您的todo
项目. - 导航到本地计算机上的
http://todo
,浏览器应显示Laravel欢迎屏幕,表明一切正常.
- 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
您现在可以在本地计算机上修改项目文件,更改将反映在VM上,反之亦然.
You can now modify your project files on your local machine and the changes will be reflected on the VM and vice versa.
这篇关于如何在Homestead和我的本地计算机之间创建共享文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!