How to implement Name Based Virtual Host on Debian 11.3
- 00:28 lsb_release -a
- 00:36 sudo -s
- 00:42 cd /
- 00:51 apt install apache2
- 01:10 systemctl start apache2
- 01:23 systemctl status apache2
- 02:11 cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example1.com.conf
- 02:52 cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example2.com.conf
- 03:28 nano /etc/apache2/sites-available/example1.com.conf
- 04:15 nano /etc/apache2/sites-available/example2.com.conf
- 04:51 mkdir /var/www/html/example1
- 05:15 mkdir /var/www/html/example2
- 05:33 nano /var/www/html/example1/index.html
- 06:49 nano /var/www/html/example2/index.html
- 07:58 a2ensite example1.com.conf
- 08:10 a2ensite example2.com.conf
- 08:28 systemctl restart apache2
- 08:42 nano /etc/hosts
- 09:40 systemctl restart apache2
To Implement Name Based Virtual Host on Debian 11.3
Introduction
In Apache, virtual hosting is the concept of hosting multiple sites within a single server, there are two types of virtual hosting, IP address hosting and domain hosting, so we can host either IP addresses or domain names.
Installation Procedure:
Step 1 : Check the OS version by using the below command
linuxhelp@linuxhelp:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Step 2 : Change as root user by using the below command
linuxhelp@linuxhelp:~$ sudo -s
Step 3 : Change the directory to root by using the below command
root@linuxhelp:/home/linuxhelp# cd /
Step 4 : Installing apache web server
root@linuxhelp:/# apt install apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
0 upgraded, 8 newly installed, 0 to remove and 254 not upgraded.
Need to get 1,739 kB of archives.
After this operation, 7,550 kB of additional disk space will be used.
Step 5 : Next start and Check the Status from apache2 by using the below commands
root@linuxhelp:/# systemctl start apache2
root@linuxhelp:/# systemctl status apache2
Step 6 : Open the browser and ping the IP address as shown in the below image

Step 7 : Copying the default virtual host .conf file example1.com virtual host
root@linuxhelp:/# cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example1.com.conf
Step 8 : Copying the default virtual host .conf file example2.com virtual host
root@linuxhelp:/# cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example2.com.conf
Step 9 : Configure the virtual host for example1.com
root@linuxhelp:/# nano /etc/apache2/sites-available/example1.com.conf

Step 10 : Configure the virtual host for example2.com
root@linuxhelp:/# nano /etc/apache2/sites-available/example2.com.conf

Step 11 : Making document Root directory as example1
root@linuxhelp:/# mkdir /var/www/html/example1
Step 12 : Making document Root directory as example2
root@linuxhelp:/# mkdir /var/www/html/example2
Step 13 :Making the index.html file for example1.com
root@linuxhelp:/# nano /var/www/html/example1/index.html

Step 14 : Making the index.html file for example1.com
root@linuxhelp:/# nano /var/www/html/example2/index.html

Step 15 : Enabling virtual host site example1.com.
root@linuxhelp:/# a2ensite example1.com.conf
Enabling site example1.com.
To activate the new configuration, you need to run:
systemctl reload apache2
Step 16 : Enabling virtual host site example2.com.
root@linuxhelp:/# a2ensite example2.com.conf
Enabling site example2.com.
To activate the new configuration, you need to run:
systemctl reload apache2
Step 17 : Restart the apache server
root@linuxhelp:/# systemctl restart apache2
Step 18 : Put host entries for virtual hosts
root@linuxhelp:/# vi /etc/hosts
192.168.6.137 www.example1.com
192.168.6.137 www.example2.com
Step 19 : Restart the apache server
root@linuxhelp:/# systemctl restart apache2
Step 20 : Next Go to the Browser Ping the www.example1.com
Step 21 : Open new tab Ping the www.example2.com

Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to Implement Name Based Virtual Host on Debian 11.3. Your feedback is much welcome.
Comments ( 0 )
No comments available