laravel Homestead:文件夹映射到错误的文档根目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25777389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:05:29  来源:igfitidea点击:

Homestead: Folder mapping to the wrong document root

phplaravelvagrant

提问by jkjmr6

I'm using Laravel Homestead to VM into my dev environment. I recently created a new mapping (the /Website/Site/directory) in my Homestead.yaml whenever I go to site.apppage , I'm redirected to the /tasks page which was set in another project (/Laravel). (This results in an error, since the page isn't there). Here is my Homestead.yaml file:

我正在使用 Laravel Homestead 虚拟机进入我的开发环境。我最近/Website/Site/在我的 Homestead.yaml 中创建了一个新的映射(目录),每当我转到site.apppage 时,我都会被重定向到在另一个项目 ( /Laravel) 中设置的 /tasks 页面。(这会导致错误,因为该页面不存在)。这是我的 Homestead.yaml 文件:

folders:
   - map: /Users/me/Homestead/Code/Laravel
     to: /home/vagrant/Code/Laravel
   - map: /Users/me/Homestead/Code/Larabook
     to: /home/vagrant/Code/Larabook
   - map: /Users/me/Homestead/Code/Website/Site
     to: /home/vagrant/Code/Website

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public
    - map: larabook.app
      to: /home/vagrant/Code/Larabook/public
    - map: site.app
      to: /home/vagrant/Code/Website/public

variables:
   - key: APP_ENV
     value: local

The Laravel contains the route where the index page is redirected and the Website directory is the new project that is just a fresh install of Laravel and nothing else. Here is some of the Server/Request Data error output:

Laravel 包含重定向索引页面的路径,而网站目录是新项目,它只是 Laravel 的全新安装,没有别的。以下是一些服务器/请求数据错误输出:

SCRIPT_FILENAME /home/vagrant/Code/Laravel/public/index.php
SCRIPT_NAME     /index.php
REQUEST_URI     /tasks
DOCUMENT_URI    /index.php
DOCUMENT_ROOT   /home/vagrant/Code/Laravel/public

Here is the route.php for the project in Laravel/ (i.e. the old project)

这是Laravel/中项目的route.php(即旧项目)

 Route::get('/', function(){
    return Redirect::to('tasks');
 });

Why is a fresh install of Laravel being redirected by a project in a different directory?

为什么全新安装的 Laravel 会被不同目录中的项目重定向?

SOLUTION

解决方案

  1. vagrant reload --provision
  1. vagrant reload --provision

or, more drastically

或者,更彻底

  1. from ~/Homesteadrun vagrant destroythen vagrant up
  1. ~/Homestead运行vagrant destroyvagrant up

回答by mike

I ran into this issue too.

我也遇到了这个问题。

Presumedly, the changes in Homestead.yamlfile are being ignored. So, I resolved to refresh it.

据推测,Homestead.yaml文件中的更改被忽略。所以,我决定刷新它。

! REVISED SOLUTION THAT DOES NOT DESTROY YOUR MACHINE

!不会损坏您的机器的修订解决方案

My solution below is inadequate because it destroys your existing machine. See this solution first!

我下面的解决方案是不够的,因为它会破坏您现有的机器。先看看这个解决方案!

Once your Homestead environment is provisioned and running, you may want to add additional Nginx sites for your Laravel applications. You can run as many Laravel installations as you wish on a single Homestead environment. There are two ways to do this: First, you may simply add the sites to your Homestead.yaml file and then run vagrant provision.

Alternatively, you may use the serve script that is available on your Homestead environment. To use the serve script, SSH into your Homestead environment and run the following command...

一旦你的 Homestead 环境被配置并运行,你可能想要为你的 Laravel 应用程序添加额外的 Nginx 站点。您可以在单个 Homestead 环境中运行任意数量的 Laravel 安装。有两种方法可以做到这一点:首先,您可以简单地将站点添加到 Homestead.yaml 文件中,然后运行 ​​vagrant provision。

或者,您可以使用 Homestead 环境中可用的服务脚本。要使用服务脚本,请通过 SSH 连接到您的 Homestead 环境并运行以下命令...

http://laravel.com/docs/homestead#daily-usage

http://laravel.com/docs/homestead#daily-usage

Per the Laravel.io forumthe better solution is to run vagrant reload --provision.

根据Laravel.io 论坛,更好的解决方案是运行vagrant reload --provision.

See also

也可以看看

*Vagrant Docs

*流浪文档

OLD SOLUTIONS: USE AS LAST RESORT

旧解决方案:用作最后的手段

Try these solutions:

尝试这些解决方案:

  1. from ~/Homesteadrun vagrant reloadthen vagrant up
  1. ~/Homestead运行vagrant reloadvagrant up

or, more drastically

或者,更彻底

  1. from ~/Homesteadrun vagrant destroythen vagrant up
  1. ~/Homestead运行vagrant destroyvagrant up

OPTION 2 DESTROYS YOUR SERVER AND ITS DATABASES

选项 2 破坏您的服务器及其数据库

Note: I resorted to step 2.

注意:我采用了第 2 步。

回答by bcdennis72

You can run homestead up --provisionto force the reload of the Homestead.yaml file.

您可以运行homestead up --provision以强制重新加载 Homestead.yaml 文件。

回答by Sir Cringe

If you have a running homestead instance, simply issue the command homestead provisionfrom your local machine.

如果您有一个正在运行的宅基地实例,只需homestead provision从本地机器发出命令。

回答by user2131283

I could fix that issue using the servecommand provided with the homestead box. When you're connected to the VM run:

我可以使用serve宅基地盒提供的命令来解决这个问题。当您连接到 VM 时,运行:

serve personal.local /home/vagrant/projects/personal/personal-site/public

serve personal.local /home/vagrant/projects/personal/personal-site/public

without the need to reboot the VM. I've tried vagrant reload --provisionand it reloads the yaml file but seems not the ngnix configuration.

无需重新启动 VM。我试过了vagrant reload --provision,它重新加载了 yaml 文件,但似乎不是 ngnix 配置。