virtual host

Recently I have received a call from my friend regarding the Virtual Hosts setup. Down below, I scribbled his question for you to read. In summary, all he need is to set up a virtual host on his VPS, so that he can host just one more blog without spending any more on hosting.

Question: I have purchased a Virtual Private Server(VPS) to host my private web site. I then mapped my domain to the VPS hosting space by making changes in the DNS settings of the domain. I created a new A record with IP addresss provided by the VPS service provider. In the server, I have deployed all the web pages in the root folder of apache (var/www/html) and everything seems working fine. I can reach my site without any problems. However, I also want to set up another blog for my wife but don’t want to spend on hosting. What I decided is to share the VPS. Please show me the steps to set up multiple web sites on a VPS.

We can host multiple sites on a VPS using apache virtual hosts. In this post I’m gonna show you how exactly I had set up hosting for our two domains in our VPS server.

To follow along this tutorial, I assume you’ve successfully installed apache web server on your server machine. In my box, apache is running its default settings and I deployed the some web pages at the root document folder (/var/www/html). I also made changes in the DNS settings of our domain to point it to the vps hosting.

So, at this point, If I type beta.yourdomain.com, then apache will successfully render all pages to my browser.

Make changes in DNS settings.

As a first step, you need to create a new A record in the Domain’s DNS that points to your VPS server. So if you have two domains, let say beta.yourdomain.com and blog.yourdomain.com, then create two A records

creating an A record in godaddy DNS

Create Virtual Hosts in VPS

Before we jump into any configuration, we need to create a new directory to keep the new website’s pages. Later on, this new directory will become the Document Root for the new site in the configuration file.

sudo mkdir /var/www/html/blog

After creating the directory, make sure to give the require permission upon it.