在 Laravel 中设置 DocumentRoot
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23016788/
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
Setting the DocumentRoot in Laravel
提问by Malchesador
I am wanting to host multiple laravel projects as subfolders within a domain, so for one project the laravel code base would reside at somedomain.com/project1 and another project at somedomain.com/project2, and so on.
我想将多个 laravel 项目作为域中的子文件夹托管,因此对于一个项目,laravel 代码库将位于 somedomain.com/project1 和另一个项目位于 somedomain.com/project2,依此类推。
Is there a way to tell laravel that the document root is actually in a subfolder of the top level directory of the domain rather than the top level directory itself?
有没有办法告诉 laravel 文档根目录实际上位于域顶级目录的子文件夹中,而不是顶级目录本身?
I had previously setup each project as a 2nd level domain with each having it's own DocumentRoot config in Apache VirtualHost directives (such as project1.somedomain.com & project2.somedomain.com), but I want to switch to using subdirectories and have one top level directory as the Apache DocRoot and the individual projects as subfolders.
我之前已将每个项目设置为第二级域,每个项目在 Apache VirtualHost 指令(例如 project1.somedomain.com 和 project2.somedomain.com)中都有自己的 DocumentRoot 配置,但我想切换到使用子目录并有一个顶部level 目录作为 Apache DocRoot,各个项目作为子文件夹。
What is the best way to do this?
做这个的最好方式是什么?
回答by alexrussell
Yes this is possible. There are a few howevers though.
是的,这是可能的。不过也有一些。
First off, normally you'd put laravel's public
directory as your webserver's document root. In this case you'd rename the public
directory to be the name of the subfolders.
首先,通常您会将 Laravel 的public
目录作为您的网络服务器的文档根目录。在这种情况下,您将public
目录重命名为子文件夹的名称。
You also need to ensure that your Laravel code (i.e. not public
) is an extra level back from the public
folder (so you keep your code away from possible access). You'll probably want to put the two separate apps in their own folders too. Now change all the paths in index.php and the paths.php file to make sure that each application points at the right supporting code.
您还需要确保您的 Laravel 代码(即不是public
)是从public
文件夹返回的额外级别(因此您可以使您的代码远离可能的访问)。您可能也希望将这两个独立的应用程序放在它们自己的文件夹中。现在更改 index.php 和paths.php 文件中的所有路径,以确保每个应用程序都指向正确的支持代码。
You'll end up with something like this:
你最终会得到这样的结果:
/path/to/docroot-parent/
app1/
app/
bootstrap/
paths.php
('public' => __DIR__.'/../../actualdocroot/app1'
)
- ...
app2/
app/
bootstrap/
paths.php
('public' => __DIR__.'/../../actualdocroot/app2'
)
- ...
actualdocroot/
← webserver points here as docrootapp1/
css/
js/
index.php
(points to../../app1/bootstrap/autoload.php
and../../app1/bootstrap/start.php
)
app2/
css/
js/
index.php
(points to../../app2/bootstrap/autoload.php
and../../app2/bootstrap/start.php
)
/path/to/docroot-parent/
app1/
app/
bootstrap/
paths.php
('public' => __DIR__.'/../../actualdocroot/app1'
)
- ...
app2/
app/
bootstrap/
paths.php
('public' => __DIR__.'/../../actualdocroot/app2'
)
- ...
actualdocroot/
← webserver 指向这里为 docrootapp1/
css/
js/
index.php
(指向../../app1/bootstrap/autoload.php
和../../app1/bootstrap/start.php
)
app2/
css/
js/
index.php
(指向../../app2/bootstrap/autoload.php
和../../app2/bootstrap/start.php
)