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
The detailed setup steps are given below.
Step 1
Login to your AWS account and launch an ubuntu server.
Step 2
SSH into you server
$ ssh -i keypair.pem username@ipaddress
Step 3
Update & upgrade your server to get the latest packages in your server.
$ sudo apt update && sudo apt upgrade -y
Step 4
Install apache2 into the server.
$ sudo apt install apache2 -y
Step 5
Go html folder which is under var/www/ directory.
$ cd /var/www/html/
Step 6
$ sudo mkdir website1 website2
Step 7
Go website1 folder which is under var/www/html/ directory.
$ cd website1/ $ cd /var/www/html/website1
Step 8
$ sudo touch index.html
Step 9
Then edit the index file
$ sudo vim index.html
Step 10
We have just created a simple script to print Hello World !!
This is website1….
Hello World !! This is website1....
Step 11
Go website2 folder which is under var/www/html/ directory
$ cd website2/ $ cd /var/www/html/website2
Step 12
Here you can copy your website files,wordpress,magento etc
Create index.html file
$ sudo touch index.html
Step 13
Edit the file
$ sudo vim index.html
Step 14
Insert a simple script to print Hello World !! This is website2….
Hello World !! This is website2....
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.
$ cd /etc/apache2/sites-enabled/
Step 16
Now lets edit the 000.default.conf
$ sudo vim 000.defaulf.conf
Step 17
You have to delete or edit the line highlighted line.
Step 18
Now just copy and paste the below-mentioned lines.
Step 19
Save the 000.default.conf file with.
Step 20
Restart Apache2 service.
$ sudo service apache2 restart
Output
As you see when we search for..
Both show different webpage but they are hosted from a single server.
You can host any website
As a Director of Eternal Web Private Ltd an AWS consulting partner company, Nirav is responsible for its operations. AWS, cloud-computing and digital transformation are some of his favorite topics to talk about. His key focus is to help enterprises adopt technology, to solve their business problem with the right cloud solutions.
Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.