How to Create Apache Virtual Hosts on Ubuntu 20.04 /Debian 10.4

Windows Articles

How to enable and disable SMB1/SMB2 in Windows 10

Hello! Windows 10 is an operating system that integrates various protocols to ensure its use with internal and external processes. Indeed, one...

Install Wine 5 on Debian 10

Hi, folks. In this post, I will help you install Wine 5 on Debian 10. Wine is one of...

Is ReactOS a real alternative to Windows?

Oh! The eternal struggle of computer operating systems. Windows vs. GNU/Linux and Mac as a distant spectator However, there are also interesting...

How to install Firebird on Ubuntu 20.04/ 18.04?

Database management systems are sufficient for many kinds of projects. Of course, they abound with MySQL / MariaDB or PostgreSQL popular but...

How to disable Firewall in Windows Server 2019/2016

Hello! The Firewall performs an essential security task on any version of Windows Server. In fact, it has the mission of preventing...
Mel Khamlichi
Mel Khamlichihttp://www.osradar.com
Founder of Osradar, from Amsterdam Netherlands

Maybe you want to run more then1 domain on the same Server, why buying another server while its possible to run many sites on the same machine.

Let me show you in this small tutorials how to create Apache Virtual hosts on your Ubuntu 20.04 Server or Debian 10.4 .

Let me give an idea about my server :

Server = Debian 10.4

IP = 192.168.0.100

1-Install Apache

Update your server

#apt-get update 
#apt-get upgrade 

So, Install Apache on Debian or Ubuntu just with this command :

root@osradar-debian:~# apt  install  apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils ca-certificates libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libcurl4 libgdbm-compat4 libgdbm6 libjansson4 libldap-2.4-2 libldap-common liblua5.2-0 libnghttp2-14
  libperl5.28 libpsl5 librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libssh2-1 openssl perl perl-modules-5.28 publicsuffix ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser libsasl2-modules-gssapi-mit | libsasl2-modules-gssapi-heimdal libsasl2-modules-ldap libsasl2-modules-otp libsasl2-modules-sql perl-doc libterm-readline-gnu-perl
  | libterm-readline-perl-perl make libb-debug-perl liblocale-codes-perl openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils ca-certificates libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libcurl4 libgdbm-compat4 libgdbm6 libjansson4 libldap-2.4-2 libldap-common liblua5.2-0
  libnghttp2-14 libperl5.28 libpsl5 librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libssh2-1 openssl perl perl-modules-5.28 publicsuffix ssl-cert
0 upgraded, 30 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.1 MB of archives.
After this operation, 60.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Now, you have to enable and start Apache. To do it, run the following commands.

root@osradar-debian:~# systemctl enable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2
root@osradar-debian:~# systemctl start apache2

So, Open your web browser and go to http://localhost or http://your-server

This is the standard home page of Apache. So, Apache is installed..

Now the change is we have to configure to sites on the same servers

www.fbi.gov
www.cia.gov 

So, Let us create and define the folders to the new virtualhosts:

root@osradar-debian:~# mkdir /var/www/html/fbi
root@osradar-debian:~# mkdir /var/www/html/cia

Then, create a new index.html file for the FBI site:

vi /var/www/html/fbi/index.html

And add the following:

<html>
 <head>
 <title>www.fbi.gov</title>
 </head>
 <body>
 <h1>Hello, Welcome to www.fbi.com  website</h1>
 </body>
</html>

Now, do the same with the the CIA site:

vi /var/www/html/cia/index.html

Again, add this content.

<html>
 <head>
 <title>www.cia.gov</title>
 </head>
 <body>
 <h1>Hello, Welcome to www.cia.com  website</h1>
 </body>
</html>

Create site configurations

The next step is create the new configurations file to the new Virtualhosts:

vi /etc/apache2/sites-available/cia.conf

So, add the following:

<VirtualHost *:80>
    ServerAdmin webmaster@cia.gov
    ServerName cia.gov
    ServerAlias www.cia.gov
    DocumentRoot /var/www/html/cia

 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Now, it is the FBI’s turn:

vi /etc/apache2/sites-available/fbi.conf

Add the following:

<VirtualHost *:80>

    ServerAdmin webmaster@fbi.gov
    ServerName fbi.gov
    ServerAlias www.fbi.gov
    DocumentRoot /var/www/html/fbi

 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Save the changes and close the file.

To enable newly created virtual hosts run the following commands as the root user:

a2ensite fbi
a2ensite cia

Restart or Reload Apache

systemctl reload apache2

Lets make an test from another server / machine

add this to the hosts file

From linux

add to the /etc/hosts file

192.168.0.100 cia.gov fbi.gov

For windows add the same to c:\windows\system32\drivers\etc\hosts

Are y ready ?

For LEMP full install please visit How to install LEMP on Ubuntu 20.04

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to enable and disable SMB1/SMB2 in Windows 10

Hello! Windows 10 is an operating system that integrates various protocols to ensure its use with internal and external processes. Indeed, one...

Install Wine 5 on Debian 10

Hi, folks. In this post, I will help you install Wine 5 on Debian 10. Wine is one of...

Is ReactOS a real alternative to Windows?

Oh! The eternal struggle of computer operating systems. Windows vs. GNU/Linux and Mac as a distant spectator However, there are also interesting...

How to install Firebird on Ubuntu 20.04/ 18.04?

Database management systems are sufficient for many kinds of projects. Of course, they abound with MySQL / MariaDB or PostgreSQL popular but...

How to disable Firewall in Windows Server 2019/2016

Hello! The Firewall performs an essential security task on any version of Windows Server. In fact, it has the mission of preventing...