logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: How to run multiple web-sites on localhost with Apache
Author
cadol_AL



Joined: 23 Jun 2023
Posts: 3
Location: Canada, Toronto

PostPosted: Fri 23 Jun '23 18:01    Post subject: How to run multiple web-sites on localhost with Apache Reply with quote

Hello everybody!

Please help a newbie. I've recently installed LAMP on Ubuntu 22.04.
Apache version: 2.4.52

What I am trying to do is to enable multiple web-sites on my localhost. I’ve read and followed a few posts on this topic however I can’t make it work.

So this is what I’ve done so far to create two sites "prj1" and "prj2":


1. Created two folders

Code:
sudo mkdir /var/www/prj1
sudo mkdir /var/www/prj2




2. Created two index files in the folders:

Code:
sudo gedit /var/www/prj1/index.html
sudo gedit /var/www/prj2/index.html


They are simple, the first states:

Code:
Web prj 1. Location:
<BR>
/var/www/prj1


The second:

Code:
Web prj 2. Location:
<BR>
/var/www/prj2


3. Set permissions:

Code:
sudo chown -R www-data:www-data /var/www
sudo chown -R 775 /var/www
sudo chown -R www-data:www-data /var/www/prj1
sudo chown -R www-data:www-data /var/www/prj2




4. Created .conf files for each project:
sudo gedit /etc/apache2/sites-available/prj1.conf


Code:
<VirtualHost *:80>
     ServerAdmin admin@prj1
     ServerName prj1
     
     DocumentRoot /var/www/prj1/
     <Directory />
      Options FollowSymLinks
      AllowOverride None
     </Directory>     
     <Directory /var/www/prj1/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/prj1.webdock.io_error.log
     CustomLog ${APACHE_LOG_DIR}/prj1.webdock.io_access.log combined
</VirtualHost>



sudo gedit /etc/apache2/sites-available/prj2.conf


Code:
<VirtualHost *:80>
     ServerAdmin admin@prj2
     ServerName prj2
     
     DocumentRoot /var/www/prj2/
     <Directory />
      Options FollowSymLinks
      AllowOverride None
     </Directory>     
     <Directory /var/www/prj2/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/prj2.webdock.io_error.log
     CustomLog ${APACHE_LOG_DIR}/prj2.webdock.io_access.log combined
</VirtualHost>



5. Enabled sites:

Code:
a2ensite prj1
a2ensite prj2


6. Edited apache2.conf:
sudo gedit /etc/apache2/apache2.conf

I’ve added the following:


Code:
<Directory /var/www/>
   Options Indexes FollowSymLinks
   AllowOverride All
   Require all granted
</Directory>

DocumentRoot "/var/www/prj1"
<Directory "/var/www/prj1">
            Options FollowSymLinks
            AllowOverride All
            Require all granted
</Directory>

DocumentRoot "/var/www/prj2"
<Directory "/var/www/prj2">
            Options FollowSymLinks
            AllowOverride All
            Require all granted
</Directory>




7. Added two lines in /etc/hosts:
sudo gedit /etc/hosts


Code:
127.0.0.1 localhost prj1
127.0.0.1 localhost prj2



8. Restarted Apache:

Code:
systemctl restart apache2



9.
Now I am using the following URL in the browser:

Code:
http://prj1.localhost/


this works as expected, it shows:


Quote:
Web prj 1. Location:
<BR>
/var/www/prj1


However if I use
Quote:
http://prj2.localhost/
it still shows the first site


Quote:
Web prj 1. Location:
<BR>
/var/www/prj1


What do I do wrong?

Thank you,
Alex
Back to top
Otomatic



Joined: 01 Sep 2011
Posts: 157
Location: Paris, France, EU

PostPosted: Sat 24 Jun '23 8:50    Post subject: Reply with quote

Hi,

In comparison with Wampserver on Windows, I think that in the hosts file, it should be :
Code:
127.0.0.1 prj1
127.0.0.1 prj2
Back to top
cadol_AL



Joined: 23 Jun 2023
Posts: 3
Location: Canada, Toronto

PostPosted: Sat 24 Jun '23 12:58    Post subject: Reply with quote

Hi Otomatic,

Thank you! Just tried, still not working...
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7298
Location: Germany, Next to Hamburg

PostPosted: Mon 26 Jun '23 11:24    Post subject: Reply with quote

Become the root user and check what vhosts are seen by Apache

Code:

sudo su -
source /etc/apache2/envvars
/usr/sbin/apache2ctl -S
Back to top
cadol_AL



Joined: 23 Jun 2023
Posts: 3
Location: Canada, Toronto

PostPosted: Mon 26 Jun '23 13:04    Post subject: Reply with quote

Hi James Blond,

First, let me thank you for stepping in, it seems that after issuing the command you suggested now I see what the problem was.

The message after the command was:

*****
Quote:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:81 prj2 (/etc/apache2/sites-enabled/prj2.conf:1)
*:80 is a NameVirtualHost
default server prj1 (/etc/apache2/sites-enabled/prj1.conf:1)
port 80 namevhost prj1 (/etc/apache2/sites-enabled/prj1.conf:1)
port 80 namevhost test1 (/etc/apache2/sites-enabled/test1.conf:1)
alias www.test1
port 80 namevhost ws1 (/etc/apache2/sites-enabled/ws1.conf:1)
alias www.ws1
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/prj2"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

*****

It shows (line 3) that the port for prj2 was 81 not 80. Honestly I don't know how that happened, I can't even say it was a typo since the whole text was copy/pasted.
Anyways, after I changed it to 80 both sites are now working. The URLs are http://prj1 and http://prj2. The only thing is that the browser tells that connection to the sites "Not secure".

Thanks again,
Alex
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7298
Location: Germany, Next to Hamburg

PostPosted: Mon 03 Jul '23 10:29    Post subject: Reply with quote

The connection that your browser tries to open is not secure. https:// instead of HTTP://

Do you force SSL somewhere? No try a different browser.
Back to top


Reply to topic   Topic: How to run multiple web-sites on localhost with Apache View previous topic :: View next topic
Post new topic   Forum Index -> Apache