Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run multiple instances of Laravel on the same domain?

I have Apache 2.4 running on Windows Server 2012 with PHP 5.6.23 on port 8080.

Assume that the domain to my server is "serv1.example.com" I need to run 3 Laravel instances production,staging and dev using the following links

serv1.example.com:8080/production
serv1.example.com:8080/staging
serv1.example.com:8080/dev

I found another SO question which seems to be doing the same thing. But when I tried to do the same thing I get the following error

Forbidden

You don't have permission to access /dev on this server.

Here is what I have done so far. In my httpd-vhosts.conf file I added the following VirtualHost

<VirtualHost *:8080>

    ErrorLog "logs/dev-error.log"
    CustomLog "logs/dev-access.log" common
    DocumentRoot "C:\www\dev\public"
    ServerName serv1.example.com
    ServerAlias /dev

    <Directory "C:\www\dev">
        Options Indexes Includes FollowSymLinks MultiViews
        AllowOverride AuthConfig FileInfo Indexes
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

Then I changed c:\www\dev\public\.htaccess the code to the following

<IfModule mod_rewrite.c>
    #Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /dev/index.php/?$1 [L]
</IfModule>

What did I do wrong here? how can I access each instance using the same domain?

like image 771
Jaylen Avatar asked Nov 09 '22 13:11

Jaylen


1 Answers

Try This one, in your Apache configure file /etc/apache2/sites-available

<VirtualHost *:8080>
     ServerName  serv1.example.com
     ServerAlias serv1.example.com
     DocumentRoot "C:/www/dev/public"

     # Rewrites for pretty URLs, better not to rely on .htaccess.
     <Directory "C:/www/dev/public">
         Options All
         AllowOverride All
         Require all granted

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
        </IfModule>
     </Directory>

# Log file locations
LogLevel warn
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" common

And in your c:\www\dev\public\.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I hope this would work. for more information follow these links.Multiple laravelsites on single apache server , multiple web sites in single laravel installation

like image 174
Sachith Muhandiram Avatar answered Nov 14 '22 21:11

Sachith Muhandiram