对多个站点和每个项目安装使用无业游民和宅基地 [英] Using vagrant and homestead for multiple sites and per project installation

查看:70
本文介绍了对多个站点和每个项目安装使用无业游民和宅基地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用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

  1. 安装VirtualBox
  2. 安装无业游民
  3. vagrant box add laravel/homestead
  4. 添加宅基地
  5. 延长存储库git clone https://github.com/laravel/homestead.git Homestead
  6. 使用bash init.sh脚本在Homestead目录中创建Homestead.yaml文件
  7. 创建一个新项目laravel new projectA
  8. 需要宅基地composer require laravel/homestead
  9. 生成Vagrantfile php vendor/bin/homestead make
  10. 修改Homestead.yaml,使其IP以10结尾
  11. 创建另一个项目laravel new projectB
  12. 需要宅基地composer require laravel/homestead
  13. 生成Vagrantfile php vendor/bin/homestead make
  14. 修改Homestead.yaml,使其IP以11结尾
  15. 将这两个站点添加到主机文件sudo nano /etc/hosts => xxx.xx.xx.10 projecta.app& xxx.xx.xx.11 projectb.app
  16. 从两个目录之一开始流浪汉vagrant up
  1. Installing VirtualBox
  2. Installing Vagrant
  3. Adding homestead with vagrant box add laravel/homestead
  4. Clonging the repository git clone https://github.com/laravel/homestead.git Homestead
  5. Create Homestead.yaml file in the Homestead directory with the bash init.sh script
  6. Create a new project laravel new projectA
  7. Require homestead composer require laravel/homestead
  8. Generate Vagrantfile php vendor/bin/homestead make
  9. Modify the Homestead.yaml to have an IP that ends with 10
  10. Create another project laravel new projectB
  11. Require homestead composer require laravel/homestead
  12. Generate Vagrantfile php vendor/bin/homestead make
  13. Modify the Homestead.yaml to have an IP that ends with 11
  14. Adding those two sites to the hosts file sudo nano /etc/hosts => xxx.xx.xx.10 projecta.app & xxx.xx.xx.11 projectb.app
  15. Starting vagrant from one of the two directories vagrant up

现在,我遇到了一个问题,即只有一个项目可以实现.它始终是我叫vagrant up的地方.因此,如果我从项目A调用vagrant up,则可以访问http://projecta.apphttp://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, run bash init.sh

编辑~/.homestead/Homestead.yamlfolders属性,以与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.yamlsites属性,以使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 the init.sh file).
    • 现在,仅用一台Homestead虚拟机,您就可以运行任意数量的项目.

      Now, you can run as many project as you want with just one Homestead virtual machine.

      这篇关于对多个站点和每个项目安装使用无业游民和宅基地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆