skip to Main Content

Can we somehow do this. I am showing the example but we can change the below code.

<Location />
    DocumentRoot /var/www/html/app1/public
</Location>

<Location /app2>
    DocumentRoot /var/www/html/app2/public
</Location>

2

Answers


  1. Not specific to laravel. If you want Apache to serve files for 2 different applicatication then set up virtual hosts in the Apache config files

    # Ensure that Apache listens on ports
    Listen 80
    Listen 81
    Listen 82
    Listen 83
    
    <VirtualHost *:80>
        DocumentRoot "/www/example1"
        ServerName www.example.com
    
        # Other directives here
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot "/www/example2"
        ServerName www.example.org
    
        # Other directives here
    </VirtualHost>
    
    <VirtualHost *:81>
        DocumentRoot "/www/example3"
    
        # Other directives here
    </VirtualHost>
    
    <VirtualHost *:82>
        DocumentRoot "/www/example4"
    
        # Other directives here
    </VirtualHost>
    
    <VirtualHost *:83>
        DocumentRoot "/www/example5"
    
        # in the 'example5' folder place subfolders 'app1' and 'app2'
        # navigate in the browser to each app i.e. 127.0.0.1/example5/app1 and 127.0.0.1/example5/app2
        # Other directives here
    </VirtualHost>
    
    Login or Signup to reply.
  2. What i need ex: 192.168.1.23 will open app1 and 192.168.1.23/app2 will
    open app1

    In this case you can use the Alias directive, like so:

        <VirtualHost *:80>
            DocumentRoot /var/www/html/app1/public
    
            Alias /app2 /var/www/html/app2/public
    
            # add other directives here
        </VirtualHost>
    

    This will map the filesystem contents of /var/www/html/app2/public to /app2 while the default Document Root (/) will be /var/www/html/app1/public.

    I recommend you have a look at the documentation here, it gives a very good explanation for different solutions to your problem: https://httpd.apache.org/docs/2.4/urlmapping.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search