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

jpmg's avatar
Level 13

Two Virtual Hosts Apache + DigitalOcean + Laravel

hello everyone.

I have a problem to login in 2 app the I have in my Virtual Machine in DigitalOcean, say that my ip to login in DigitalOcean is 134.209.XXX.XXX and in my var/www I created two directory one is hidroclient and the other one is fotinclient those are my directory for my apps, I create in my apache sites-available 2 config.

hidroclient.conf

  	<VirtualHost *:80>
		ServerAdmin webmaster@localhost
		ServerName  hidroclient
		ServerAlias hidroclient
		DocumentRoot /var/www/hidroclient/public
		ErrorLog ${APACHE_LOG_DIR}/error.log
		CustomLog ${APACHE_LOG_DIR}/access.log combined
		<Directory /var/www/hidroclient/public>
    		Require all granted
    		AllowOverride All
 		</Directory>
</VirtualHost>

fotinclient.conf

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	ServerName  fotinclient
	ServerAlias fotinclient
	DocumentRoot /var/www/fotinclient/public
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
	<Directory /var/www/fotinclient/public>
    	Require all granted
    	AllowOverride All
 	</Directory>

after tha I did this two comand a2ensite hidroclient.conf a2ensite fotinclient.conf

after tha I did this comand

nano /etc/hosts 127.0.1.1 ubuntu-s-1vcpu-2gb-intel-nyc1-01 ubuntu-s-1vcpu-2gb-intel-nyc1-01 127.0.0.1 localhost 134.209.XXX.XXX hidroclient 134.209.XXX.XXX fotinclient

then i reload and restar apache

when i go to navigation bar with the address http://134.209.XXX.XXX/hidroclient i got 404 Sorry, the page you are looking for could not be found.

I don't know what i doing wrong, can someone help me?? thank you very much

0 likes
15 replies
sr57's avatar
	<Directory /var/www/html/fotinclient>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
            Require all granted
    	</Directory>

same for other site.

sr57's avatar

I think that problem is my /etc/hosts because I wrote in the navegacion bar http://134.209.XX.XXX/fotinclient and have the same error 404

Precisely, that means that it's not a pb with /etc/hosts

Method to solve such a pb.

-1- Is apache running? What's the result of http://134.209.XX.XXX ?

-2- Have you an other vhost running? If not create one with a simple index.html file.

-3- is your Laravel app in the rigth directory with the god rigths?

jpmg's avatar
Level 13

Hy sr57 I did this steps

  1. erase all .conf in my apache2/ sites-available and create another one only one in my /etc/hosts

    <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName hidroclient ServerAlias hidroclient DocumentRoot /var/www/hidroclient/public ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/hidroclient/public> Require all granted AllowOverride All

  1. erase the two lines 134.209.XXX.XXX hidroclient 134.209.XXX.XXX forticlient

  2. restart all over again

and now when i go to my personal computer and write the ip the i have in DigitalOcean like this

134.209.XXX.XXX/login it works... but only for one virtual hosts the problem is that i need two VH for two diferents logins

sr57's avatar

Ok there is progress, it's not /etc/hosts and apache is working.

First , please put your code between ```, without it's unreadable

Then share your 4 vhost config , default and simple test and your 2 Laravel apps

BTW, have you have enable your vhost (a2ensite) ?

jpmg's avatar
Level 13

Yes is working only for one Vhost..

  1. VHost hidrofliente.conf

     	<VirtualHost *:80>
     			ServerName hidrofcliente
     			ServerAlias 134.209.XXX.XXX
     			ServerAdmin jmoreno@fortincp
     			DocumentRoot /var/www/hidrofcliente/public
     			ErrorLog ${APACHE_LOG_DIR}/hidrofcliente.log
     			CustomLog ${APACHE_LOG_DIR}/hidrofcliente-access.log combined
     			<Directory /var/www/hidrofcliente/public>
     				Require all granted
     				AllowOverride All
     			</Directory>
     </VirtualHost>
    
  2. VHost forticliente.conf

     <VirtualHost *:80>
     		ServerName forticliente
     		ServerAlias 134.209.XXX.XXX
     		ServerAdmin jmoreno@fortincp
     		DocumentRoot /var/www/forticliente/public
     		ErrorLog ${APACHE_LOG_DIR}/forticliente.com.log
     		CustomLog ${APACHE_LOG_DIR}/forticliente-access.log combined
     			<Directory /var/www/forticliente/public>
     				Require all granted
     				AllowOverride All
     		</Directory>
     </VirtualHost>
    

those two files area in my virtual machine in Digital Ocean

yes I enable my two .conf files with

 a2ensite forticliente.conf
 a2ensite hidrofliente.conf

in my /etc/hosts I haven't made anything

ok now in my personal computer out off Digital Ocean in my navigation bar.

http://134.209.XXX.XXX/login it work for my first VHost but how can i make to work for both VHost?

sr57's avatar

-1- ServerAlias 134.209.XXX.XXX ! ?

You can have vhost by IP but it's another config, alias should be name, www.forticliente, myfirsite, ...

That said, maybe it works but since you put the same 'name' it redirects always to the first vhost

-2- if does not still work, change with my "<directory ... "config, I known it works.

jpmg's avatar
Level 13

Not workin I change ServerAlias with www.forticlient but I don't have the Domain i have is a virtual machine in Digital Ocean with ip 134.209.XXX.XXX not matter what I do is not working. thank you for your time sr57

sr57's avatar

Not working

It should work, be factual

  • what is the final config (3 vhost config : default and 2 Laravel apps)

  • what url you check?

jpmg's avatar
Level 13

i run this command in my virtual machine to see my virtual host running in apache.

#apache2ctl -S

and i show me this.

VirtualHost configuration:

		*:80                   is a NameVirtualHost
    	default server fortinclient.com (/etc/apache2/sites-enabled/fortinclient.conf:1)
     	port 80 namevhost fortinclient.com (/etc/apache2/sites-enabled/fortinclient.conf:1)
        alias www.fortinclient.com
     	port 80 namevhost hidrofracliente.com (/etc/apache2/sites-enabled/hidrocliente.conf:1)
        alias www.hidrofracliente.com

I try all this

http://134.209.XXX.XXX/hidrofrac.com http://134.209.XXX.XXX/fortinclient.com

show me.

404 Sorry, the page you are looking for could not be found.

but.

http://134.209.XXX.XXX/login

it works but redirect to my first virtual host

sr57's avatar

Perhaps I have misled you with my first comment about /etc/hosts.

This type of virtual host works with name, that means the name (ServerName & AliasName) you define in your vhost config will redirect to the right apps, and the name MUST (exactly the same) be in the url, so in your /etc/hosts pointed to the SAME ip (so I'll not work with ip in url)

jpmg's avatar
Level 13

so in my /etc/hosts will be like this?

134.209.XXX.XXX fortinclient 134.209.XXX.XXX hidrofracliente

and do i have to make change in my VH .conf ?

sr57's avatar

Hi @jpmg

Did you solve your problem? if you ask help it's important to give feedback.

do i have to make change in my VH .conf ?

I don't read in your server, neither your mind. What's your final setup?

jpmg's avatar
Level 13

Hello sr57 yes i know is important to give feedback I always do it, i have not resolve my problem, I reading a tutorial the DigitalOcean recommend to me

jpmg's avatar
Level 13

finally I solved the problem, first of all I have to make son change of my virtual host, because I don't have a domain I was working only in my virtual host so at las my virtual host look like this.

		<VirtualHost 134.209.XXX.XXX:80>
			ServerName hidrofrac
			ServerAlias hidrofrac
			ServerAdmin [email protected]
			DocumentRoot /var/www
			ErrorLog ${APACHE_LOG_DIR}/hidrofrac.log
			CustomLog ${APACHE_LOG_DIR}/hidrofrac-access.log combined
 			<Directory /var/www/hidrofrac/public>
  					Require all granted
  					AllowOverride All
			</Directory>
		</VirtualHost>

Please or to participate in this conversation.