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.

我try 过各种方法,但目前的主要问题是,当试图访问他们的网页时,一个项目可以工作,而所有其他项目都会获得连接超时.

以下是我使用Homestead所采取的步骤

  1. Installing VirtualBox
  2. Installing Vagrant
  3. Adding homestead with vagrant box add laravel/homestead
  4. 关闭存储库git clone https://github.com/laravel/homestead.git Homestead
  5. 创建家园.使用bash init.sh脚本在Homestead目录中创建yaml文件
  6. Create a new project laravel new projectA
  7. 需要宅地composer require laravel/homestead
  8. 生成文件php vendor/bin/homestead make
  9. Modify the Homestead.yaml to have an IP that ends with 10
  10. 创建另一个项目laravel new projectB
  11. 需要宅地composer require laravel/homestead
  12. 生成文件php vendor/bin/homestead make
  13. 修改Homestead.yaml,使其IP以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次.不幸的是,反过来也是如此.

This is my vagrant global-status

id       name    provider   state   directory                           
------------------------------------------------------------------------
fc6fadb  default virtualbox running /Users/mknb/work/projectA

I thought I would just do another vagrant up from the projectB directory but that doesn't work of course.

我不想使用global Homestead,因为拉维尔说,安装per project台是可能的,那么我该如何实现呢?你需要更多信息吗?

I didn't modify the Homestead.yaml except of the IP and the domainname homestead.app => projecta.app

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?

Starting vagrant from the Homestead directory doesn't work of course.

推荐答案

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运行多个项目,您可以执行以下操作:

  • 克隆人家园git clone https://github.com/laravel/homestead.git Homestead
  • Inside the Homestead folder, run bash init.sh

编辑~/.homestead/Homestead.yamlfolders属性,以便与VM共享这两个项目的代码:

folders:
    - map: ~/pj1
      to: /path/to/project1
    - map: ~/pj2
      to: /path/to/project2

编辑~/.homestead/Homestead.yamlsites属性,使Nginx启用两个站点的域:

sites:
    - map: project1.local
      to: /home/vagrant/pj1/public
    - map: project2.local
      to: /home/vagrant/pj2/public

Edit your hosts file to forward these domain fo localhost

127.0.0.1 project1.local
127.0.0.1 project2.local
  • 在克隆了其中的宅地代码的文件夹(其中包含init.sh文件)上运行vagrant up.

现在,只需一台Homestead虚拟机,就可以运行任意多个项目.

Laravel相关问答推荐

Laravel 通过 API 嵌套 url 发布

使用两个日期之间的范围获取两列之间的记录,同时搜索过滤条件

Laravel 如何处理来自浏览器的 PUT 请求?

Laravel 有Many Many to Many To One Eloquent

如何在 Laravel Passport 中获取刷新令牌?

Laravel 5.4 中的自定义助手类

Guzzle - Laravel如何使用 x-www-form-url-encoded 发出请求

在 laravel 5.2 中禁用特定路由的 Web 中间件

在 Laravel Eloquent 中,limit 与 take 有什么区别?

Homebrew PHP 似乎没有链接

在 Laravel 5 中找不到类App\Http\Controllers\Artisan

Laravel 4 上传图片表单

Laravel 5 - 判断日期是否是今天

Eloquent 模型不更新 updated_at 时间戳

Laravel 5 - 从控制器级别的所有请求对象中删除参数

Laravel php artisan 产生错误

如何在 Laravel 中 Refresh刷新用户对象?

将参数传递给 Laravel 中的中间件

laravel:如何获取 eloquent 模型的列名?

函数参数前的三个点代表什么?