Reputation: 795
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.
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?
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.
What is the best way to do this?
Upvotes: 4
Views: 7899
Reputation: 14212
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.
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.
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 docroot
app1/
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
)Upvotes: 2