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

Windows Articles

How to get the Nextcloud desktop client on Linux?

Hello friends. We already know how to install a Nextcloud server but now the client is missing. So in this post, you...

How to Backup your call and SMS history in Android

Many times we find ourselves in the situation of having to change our phone, for different reasons, and one of the questions...

Install and configure Apache Guacamole on Debian 10

Hello, friends in this post, you will learn how to install and configure Apache Guacamole in Debian 10. It will be a...

Ubuntu 20.10 available

The new version of Ubuntu is now available, under the code name "groovy gorilla". Ubuntu 20.10 focuses on improving and refining the...

Monitoring Ubuntu 20.04 with Stacer

Normally if we use Linux on a production server, it is important to monitor it. On the other hand, in everyday use, many users...
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 get the Nextcloud desktop client on Linux?

Hello friends. We already know how to install a Nextcloud server but now the client is missing. So in this post, you...

How to Backup your call and SMS history in Android

Many times we find ourselves in the situation of having to change our phone, for different reasons, and one of the questions...

Install and configure Apache Guacamole on Debian 10

Hello, friends in this post, you will learn how to install and configure Apache Guacamole in Debian 10. It will be a...

Ubuntu 20.10 available

The new version of Ubuntu is now available, under the code name "groovy gorilla". Ubuntu 20.10 focuses on improving and refining the...

Monitoring Ubuntu 20.04 with Stacer

Normally if we use Linux on a production server, it is important to monitor it. On the other hand, in everyday use, many users...
x