Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup several Laravel 5 projects in a subdirectory

Tags:

apache

laravel

I'm trying to setup my httpd.conf to be able to run several laravel projects in a subdirectory without constantly updating my httpd.conf for each project.

For example,

I'd like to be able to hit my site 127.0.0.1/my_projects and have several dynamic sub-directories that would launch my particular app without editing httpd.conf. Is this achievable?

like image 782
KingKongFrog Avatar asked Nov 09 '22 13:11

KingKongFrog


1 Answers

You can achieve this by using VirtualDocumentRoot.

In your case you can setup a development sub-domains to access your websites.

<VirtualHost *:80>
    ServerName testsites.localhost.com
    ServerAlias *.test.localhost.com
    VirtualDocumentRoot /var/www/dev/%1/public
</VirtualHost>

Now if you access http://project1.test.localhost.com it will point you to /var/www/dev/project1/public, http://project2.test.localhost.com will point to /var/www/dev/project2/public and etc.

In order this to work, you have to also enable the module virtual_host_alias

LoadModule vhost_alias_module modules/mod_vhost_alias.so

Note that you have to put entries in your /etc/hosts for your sub-domains and point them to be resolved by 127.0.0.1.

127.0.0.1    project1.test.localhost.com
127.0.0.1    project2.test.localhost.com

If you don't want to write an entry for each of your sub-domains in the hosts file you can consider to setup a simple DNS server, where you can wildcard all of your sub-domains *.test.localhost.com and tell them to resolve to 127.0.0.1

You can read more about dynamic virtual hosts here.

like image 128
Sh1d0w Avatar answered Nov 15 '22 07:11

Sh1d0w