How to Create a Virtual Host: A Step-By-Step Guide

Let’s create a virtual host by using the Apache hosts and the Ubuntu OS. We use both of these because they are user-friendly, reliable, and most trusted.

Step 1: Update The Softaware

  • The prerequisites for the creation of a virtual host are Ubuntu OS and Apache installation. You can do it using the following commands if you don’t have Apache installed.

sudo apt-get update

Step 2: Install Apache Software

Now, install the apache software on the operating system such as Ubuntu with the following command:

sudo apt-get install apache2

  • Let’s start with the step-by-step process.

Step 3: Directory structure creation

  • In the first step, we will create a directory structure to store the website data or accept data from visitors. You need to use the following command under the document root – /var/www directory.
sudo mkdir -p /var/www/app2.pranshtech.com/public_html

Step 4: Give Permissions

  • Generally, root users have ownership of the directory structure. However, you can change it using the following command.
sudo chown -R $USER : $YOUR_USER_NAME/var/www/app2.pranshtech.com/public_html

Step 5: Creation of the demo page for every virtual host

  • Now, we will create a sample test page for pranshtech.com. To create it, you can use vi or any other editor.
  • Type the following command to create the demo page for pranshtech.com

vi /var/www/app2.pranshtech.com/public_html/index.html

  • In the index.html file, you need to type the following basic HTML code.

<html>

<head>

<title>Home Page of pranshtech.com <title>

</head>

<body>

<h1>Hurrah! The virtual host of app2. pranshtech.com is working properly. </h1>

</body>

</html>

Step 6: New file setup

  • Apache contains the default host configuration file named 000-default.conf. We will use the same to set up the new file for our virtual host.
  • So, let’s copy this file to pranshtech.com using the following command.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sitesavailable/pranshtech.conf
  • Once the file is copied, you can open it using your preferred editor.

<VirtualHost *:80>

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

  • Now, change the email address. ServerAdmin admin@pranshtech.com , In the next step, add ServerName and ServerAlias using the following command.
ServerName  pranshtech.com
ServerAlias www.app2.pranshtech.com
  • Now, the final step is to change the document root’s location. Use this command for it.

DocumentRoot /var/www/app2.pranshtech.com/public_html.

Step 7: File Enabling

  • Let’s enable our virtual files through the following command.

sudo a2ensite app2.pranshtech.com.conf

  • Once it is done, you need to restart the Apache server.

sudo service apache2 restart

Step 8: Test Web Hosting

It is result time. Open your web browser and enter pranshtech.com. You will see the result like this –

Hurrah! The virtual host of pranshtech.com is working properly.

How Does Virtual Hosting Works?

Your tech stack’s performance and speed greatly matter in today’s tech-centric digital era. Investing in these tools is quite expensive as it costs thousands of bucks to maintain them. That’s why, as a business owner, you can make a prudent decision to find some middle ways to get things done in zero-to-nominal investments.

One such way is to opt for virtual web hosting, as it will help you cut your IT costs. And the best thing about virtual hosting is that you don’t need to compromise on quality. Virtual web hosting lets you have your business’s online presence without much tech knowledge and resources. Without further ado, let’s dive into it.

Similar Reads

What is Virtual Web Hosting?

The concept of virtual hosting began in the late 1990s. In the 1990s, server technology was improved. One physical server was divided into multiple virtual servers. This cutting-edge technology revolutionized the entire web hosting industry. Now, one question will surely pop into your mind – what is virtual web hosting? Let’s understand it briefly in layperson’s terms....

How does virtual web hosting work?

The concept of virtual web hosting is simple. It lets multiple websites live on a single physical server. It simply means effective usage of the resources with minimum investments. We have summarized the main virtual web hosting concepts in the tabular format below....

What is a Server?

It is a computer on which your web host stores the required files and databases your website needs. Whenever any visitor or user wants access to your website, the browser sends a request to your server. Once your server accepts the request, it transfers the required files online. Now, let’s understand how virtual web hosting works....

How Does Virtual Hosting Work?

In virtual hosting, you will get a virtual server. This virtual server acts as a physical server. However, the reality is different. The main physical server is shared among several users through a hypervisor. Virtualization technique is used to create these virtual servers. In this technique, virtualization software isolates the OS from the computer hardware (main physical server). So, the host machine hardware can individually operate various guest virtual machines. The main physical server can share resources like network bandwidth, disk space, RAM, etc....

Advantages Of Virtual Web Hosting

The Virtual web hosting offers various benefits, a few are listed as follows:...

Different Ways To Configure Virtual Hosting

There are three different ways in which you can create a virtual host....

How to Create a Virtual Host: A Step-By-Step Guide

Let’s create a virtual host by using the Apache hosts and the Ubuntu OS. We use both of these because they are user-friendly, reliable, and most trusted....

Challenges You Will Experience With Virtual Web Hosting

Virtual web hosting also has its own set of cons. The main three issues or challenges with virtual web hosting are:...

How Do You Troubleshoot Virtual Hosting Challenges?

If you experience slow website performance, you need to optimize the code. Besides, keep your plugins and software up-to-date. Upgrade the server resources whenever required. It will help you improve your website speed and resolve compatibility issues. Upgrade security measures and implement SSL certificates. Use strong passwords and also back up your data regularly. Keep yourself updated about potential threats....

Power Of Virutal Web Hosting

Virtual web hosting is an excellent option for businesses that want to set up and grow their online presence but don’t need to spend a hefty amount on resources and tools. With virtual hosting, businesses can share their resources on a single server and enjoy scalability and cost savings....

Virtual Hosting – FAQs

What is virtual hosting?...