问题描述
我已经使用XAMPP已有一段时间了,在发现Laravel并发现自己非常喜欢它之后,我也想使用Homestead.我遇到的问题是,我似乎无法运行多个站点.
I have been using XAMPP for quite a time, and after discovering Laravel and finding out, that I quite like it, I also wanted to use Homestead. The problem I'm having is, that I can't seem to be able to run multiple sites.
我已经尝试了各种方法,但是当前的主要问题是,一个项目可以正常工作,而其他所有项目都在尝试访问其网页时出现连接超时的情况.
I have tried various things, but the main problem currently is, that one project works, while all the others are getting a connection timeout, when trying to access their webpage.
这些是我使用Homestead所采取的步骤
These are the steps I've taken to use Homestead
- 安装VirtualBox
- 安装无业游民
- 用
vagrant box add laravel/homestead
添加宅基地 - 延长存储库
git clone https://github.com/laravel/homestead.git Homestead
- 使用
bash init.sh
脚本在Homestead
目录中创建Homestead.yaml文件 - 创建一个新项目
laravel new projectA
- 需要宅基地
composer require laravel/homestead
- 生成Vagrantfile
php vendor/bin/homestead make
- 修改Homestead.yaml,使其IP以10结尾
- 创建另一个项目
laravel new projectB
- 需要宅基地
composer require laravel/homestead
- 生成Vagrantfile
php vendor/bin/homestead make
- 修改Homestead.yaml,使其IP以11结尾
- 将这两个站点添加到主机文件
sudo nano /etc/hosts
=>xxx.xx.xx.10 projecta.app
&xxx.xx.xx.11 projectb.app
- 从两个目录之一开始流浪汉
vagrant up
- Installing VirtualBox
- Installing Vagrant
- Adding homestead with
vagrant box add laravel/homestead
- Clonging the repository
git clone https://github.com/laravel/homestead.git Homestead
- Create Homestead.yaml file in the
Homestead
directory with thebash init.sh
script - Create a new project
laravel new projectA
- Require homestead
composer require laravel/homestead
- Generate Vagrantfile
php vendor/bin/homestead make
- Modify the Homestead.yaml to have an IP that ends with 10
- Create another project
laravel new projectB
- Require homestead
composer require laravel/homestead
- Generate Vagrantfile
php vendor/bin/homestead make
- Modify the Homestead.yaml to have an IP that ends with 11
- Adding those two sites to the hosts file
sudo nano /etc/hosts
=>xxx.xx.xx.10 projecta.app
&xxx.xx.xx.11 projectb.app
- Starting vagrant from one of the two directories
vagrant up
现在,我遇到了一个问题,即只有一个项目可以实现.它始终是我叫vagrant up
的地方.因此,如果我从项目A调用vagrant up
,则可以访问http://projecta.app
和http://projectb.app
超时.不幸的是,反之亦然.
Now, I'm having the problem, that only one of the projects is reachable. It's always the one from where I called vagrant up
. So if I call vagrant up
from Project A I can access http://projecta.app
and http://projectb.app
times out. The same the other way around, sadly.
这是我的vagrant global-status
id name provider state directory
------------------------------------------------------------------------
fc6fadb default virtualbox running /Users/mknb/work/projectA
我以为我会从projectB
目录中再执行另一个vagrant up
,但这当然行不通.
I thought I would just do another vagrant up
from the projectB
directory but that doesn't work of course.
我不想使用全局Homestead,因为Laravel表示可以安装per project
,所以我该如何实现呢?您需要更多信息吗?
I don't want to use the global Homestead, because Laravel said, that it is possible to have a per project
installation, so how do I achieve it? Do you need more information?
除了IP和域名homestead.app
=> projecta.app
I didn't modify the Homestead.yaml
except of the IP and the domainname homestead.app
=> projecta.app
使用Homestead进行全局安装似乎很容易,因为我只需要向Homestead.yaml添加更多站点,但是正如我所说,我希望按项目进行安装.有人可以帮忙吗?
It seems like a global installation is fairly easy with Homestead, since I would just have to add more sites to the Homestead.yaml, but as I said I'd like to have a per project installation. Can anybody help?
从Homestead目录启动流浪汉当然是行不通的.
Starting vagrant from the Homestead directory doesn't work of course.
推荐答案
通过使用Homestead,您可以为每个项目创建一个虚拟机.因此,VirtualBox无法转发来自主机的虚拟机全部的HTTP请求.每次只能运行一台机器(因此,一个项目).
By using Homestead in your way, you create a virtual machine for each projects. Therefore, the VirtualBox cannot forward the HTTP request from your host machine for all of virtual machine. You can only run one machine (so, one project) each time.
要使用Homestead运行多个项目,您可以执行以下操作:
To run multiple projects with Homestead, you can do as follow:
- 克隆宅基
git clone https://github.com/laravel/homestead.git Homestead
- 在
Homestead
文件夹中,运行bash init.sh
- Clone Homestead
git clone https://github.com/laravel/homestead.git Homestead
- Inside the
Homestead
folder, runbash init.sh
编辑~/.homestead/Homestead.yaml
的folders
属性,以与VM共享两个项目的代码:
Edit the folders
property of ~/.homestead/Homestead.yaml
to share your code of both projects with VM:
folders:
- map: ~/pj1
to: /path/to/project1
- map: ~/pj2
to: /path/to/project2
编辑~/.homestead/Homestead.yaml
的sites
属性,以使Nginx启用两个站点的域:
Edit the sites
property of ~/.homestead/Homestead.yaml
to make Nginx enable the domain of both site:
sites:
- map: project1.local
to: /home/vagrant/pj1/public
- map: project2.local
to: /home/vagrant/pj2/public
编辑您的hosts
文件以将这些域转发给本地主机
Edit your hosts
file to forward these domain fo localhost
127.0.0.1 project1.local
127.0.0.1 project2.local
- 在其中克隆Homestead代码的文件夹(包含
init.sh
文件)上运行vagrant up
. - Run
vagrant up
at the folder that you cloned the Homestead code inside it (which contains theinit.sh
file).
现在,仅用一台Homestead虚拟机,您就可以运行任意数量的项目.
Now, you can run as many project as you want with just one Homestead virtual machine.
这篇关于对多个站点和每个项目安装使用无业游民和宅基地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!