Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vandyczech's avatar

Multiple Laravel projects on the same webserver

I have webserver on apache2 and I need host two Laravel projects. Alpha and Beta. The problem is, that I have only public IP address 192.168.1.46 but I cant set the ServerName or Alias ...

I need show the first Laravel project Alpha on 192.168.1.46 and second project Beta on 192.168.1.46:8080, but it seems that, when the composer is installed globally, its important separate these projects. How can I configure this, especially .htaccess file.

When put 192.168.1.46 I need htaccess direct into the /var/www/alpha/public/index.php When put 192.168.1.46:8080, I need htaccess direct into the /var/www/beta/public/index.php

Alpha
/var/www/alpha 

Beta
/var/www/beta

Please help me some solution ... thank you for advice ...

0 likes
14 replies
willvincent's avatar

You'd be better off doing this with named hosts.

If you configure the vhosts to accept by name, then you could have something like this...

Listen 80
<VirtualHost *:80>
    DocumentRoot "/var/www/alpha/public"
    ServerName alpha.dev

    # Other directives here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/beta/public"
    ServerName beta.dev

    # Other directives here
</VirtualHost>

Then in your hosts file (on your local machine):

192.168.1.46    alpha.dev beta.dev

This will allow you to hit either site, by name, and point to the appropriate doc root.

1 like
vandyczech's avatar

@willvincent: Maybe you do not read what I wrote. I have publish IP and I need solution for this ... 192.168.1.46 via ports.

willvincent's avatar

I did read what you wrote, I'm telling you there's a better way.

But, if you're convinced ports are the right solution, something like this for the apache config should work:

Listen 80
Listen 8080
<VirtualHost *:80>
    DocumentRoot "/var/www/alpha/public"
    ServerName alpha.dev

    # Other directives here
</VirtualHost>

<VirtualHost *:8080>
    DocumentRoot "/var/www/beta/public"
    ServerName beta.dev

    # Other directives here
</VirtualHost>
vandyczech's avatar

But I cant use alpha.dev, i have only public IP address, not domain .... :) The problem is in Laravel, Virtualhost works, but htaccess not, because Laravel reference to the one project and another doesnt work ... Especially, i need know how look htaaccess.

RuinSain's avatar

As said here before, in every folder you put a laravel project, you need to move nall the content of the public folder to the root folder of your project. This video shows it... just do it for every project you want. https://www.youtube.com/watch?v=c9H2OPRC8m4

Snapey's avatar

@RuinSain

As said here before, in every folder you put a laravel project, you need to move nall the content of the public folder to the root folder of your project.

No, you do not. You just need to make sure that Apache serves your public folder as the web root folder.

Given control of apache, you DONT need to mess with the folder layout.

1 like
KennexCorp's avatar

Since one IP address can be assigned to one computer at a time,

I created a startup script on my linux machine that starts each laravel application on a different port over the network. for example

Script 1 for 1st app:

php <PATH_TO_LARAVEL_PROJECT>/artisan serve --host=<IP_ADDRESS> --port=8000

Script 2 for 2nd app:

php <PATH_TO_LARAVEL_PROJECT>/artisan serve --host=<IP_ADDRESS> --port=8001

.

.

.

Script n for n app:

php <PATH_TO_LARAVEL_PROJECT>/artisan serve --host=<IP_ADDRESS> --port=nnnn

You can do this for multiple projects over same IP address.

Snapey's avatar

@KennexCorp but we have virtual hosts for this. Your webserver can serve multiple websites on the same ip and port and use the client request headers to decide which virtual host to serve

Please or to participate in this conversation.