How to Setup Multiple Websites in a Single AWS Instance?

How to Setup Multiple Websites in a Single AWS Instance?

June 11, 2020 / Nirav Shah

If you are on a dedicated or VPS like Amazon Web Service or any other server and planning to host multiple websites on a single server then here is a short step-by-step tutorial on how you can do it with Apache HTTP web server.

There are many different ways to do this in many different software like WHM/Cpanel etc. But all of these are paid software, which will charge you approximately $20/per-month.

Before we dive into the details and you implement this, to give you an idea of how it works. The concept to have multiple websites on a single instance is called Virtual Server. Virtual server configuration is defined within web server configuration and based on server/IP address, a request is getting forwarded to respective Document Root.

And the best part is, we are going to set it up for free using AWS (though extra costs may apply depending on the AWS service that you use).
Pre-requisites.

Pre-requisites

  • AWS Account
  • Ubuntu Server
  • Domain name (s)

The detailed setup steps are given below.

Step 1

Login to your AWS account and launch an ubuntu server.

Multiple Websites Single AWS Instance

Step 2

SSH into you server

$ ssh -i keypair.pem username@ipaddress 

Multiple Websites Single AWS Instance

Step 3

Update & upgrade your server to get the latest packages in your server.

$ sudo apt update && sudo apt upgrade -y

Multiple Websites Single AWS Instance

Step 4

Install apache2 into the server.

$ sudo apt install apache2 -y

Multiple Websites Single AWS Instance

Step 5

Go html folder which is under var/www/ directory.

$ cd /var/www/html/

Multiple Websites Single AWS Instance

Step 6

  • Make the folder as the many website you want to host.
  • (In my case ) I am creating 2 folders as we want to host 2 website.
  • As website1 and website2.
$ sudo mkdir website1 website2

Multiple Websites Single AWS Instance

Step 7

Go website1 folder which is under var/www/html/ directory.

    $ cd website1/
    $ cd /var/www/html/website1

Multiple Websites Single AWS Instance

Step 8

  • Here you can copy your website files like WordPress, Magento, etc.
  • In our case, we are creating index.html file just to test.
$ sudo touch index.html

Multiple Websites Single AWS Instance

Step 9

Then edit the index file

$ sudo vim index.html

Multiple Websites Single AWS Instance

Step 10

We have just created a simple script to print Hello World !!
This is website1….


    

Hello World !! This is website1....

Multiple Websites Single AWS Instance

Step 11

Go website2 folder which is under var/www/html/ directory

$ cd website2/
$ cd /var/www/html/website2

Multiple Websites Single AWS Instance

Step 12

Here you can copy your website files,wordpress,magento etc
Create index.html file

$ sudo touch index.html

Multiple Websites Single AWS Instance

Step 13

Edit the file

$ sudo vim index.html

Multiple Websites Single AWS Instance

Step 14

Insert a simple script to print Hello World !! This is website2….


    

Hello World !! This is website2....

Multiple Websites Single AWS Instance

Step 15

Now let’s go to apache2 conf file where we will see how that is when a request comes to which domain and transfer it to which folder.
In our case, we have created 2 subdomains.

  • website1.demodomain.com website1 will show the contents of website1 folder
  • website2.demodomain.com website2 will show the contents of website2 folder
$ cd /etc/apache2/sites-enabled/

Multiple Websites Single AWS Instance

Step 16

Now lets edit the 000.default.conf

$ sudo vim 000.defaulf.conf

Multiple Websites Single AWS Instance

Step 17

You have to delete or edit the line highlighted line.

  • #ServerName www.example.com
  • ServerAdmin webmaster@localhost
  • DocumentRoot /var/www/html/

Multiple Websites Single AWS Instance

Step 18

Now just copy and paste the below-mentioned lines.

  • ServerName yourdomain
  • ServerAdmin webmaster@localhost
  • DocumentRoot /var/www/html/folder-name

Multiple Websites Single AWS Instance

Multiple Websites Single AWS Instance

  • ServerName change yourdomain to your domain name.
  • DocumentRoot edit to the location where your website is placed.

Step 19

Save the 000.default.conf file with.

  • Esc
  • : ( colon )
  • wq!

Multiple Websites Single AWS Instance

  • Then press enter

Step 20

Restart Apache2 service.

$ sudo service apache2 restart

Multiple Websites Single AWS Instance

Output

As you see when we search for..

  • website1.demodomain.com
  • website2.demodomain.com

Multiple Websites Single AWS Instance

Multiple Websites Single AWS Instance

Both show different webpage but they are hosted from a single server.

You can host any website

  • Php
  • Angular/Node
  • Html
  • WordPress
  • Magento
  • and many more…

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let Us Talk About Your AWS Development Requirements

    Have queries about your AWS project ideas and concepts? Please drop in your project details to discuss with our AWS experts, professionals and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project