Votes: 0Posted On: Nov 02, 2017 01:00:27
You can certainly host multiple websites on your dedicated server. We can achieve this with the help of Apache2 web server. Apache2 web server is one of the most popular web servers today. With the help of Apache2 web server, you can host multiple websites on a single IP address. In this case, we will be operating on Ubuntu 14.04 operating system.
We will be creating two websites abc.com and xyz.com websites and hosting them on the server.
1. Active network connection
2. Ubuntu Operating System
3. Apache2 Web server
Run the following command to install Apache2 web server.
sudo apt-get install apache2
Making Separate directories for websites
We will now make separate directories for the websites we are planning to create. Please run the following command to create the directories on the "/var/www" location.
sudo mkdir -p /var/www/abc.com/html/
sudo mkdir -p /var/www/xyz.com/html/
The directory "/var/www" can only be accessed by users with special permissions. We need to grant Apache2 these permissions so that it can manage and edit the files.
Please run the following command to achieve the same.
sudo chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www/
Creating Web pages
Now we will create a simple web page in the directories that we created earlier (/var/www/abc.com/html/).
sudo vi /var/www/abc.com/html/index.html
sudo vi /var/www/xyz.com/html/index.html
As these two directories will create separate websites, the web pages created on file index.html will be displayed on these websites.
Just a test case, we will display the simplest of web page. You can create the web page as per your requirement.
This is abc.com
You can do the same for "xyz.com".
Virtual Host File Creation
After the Apache2 web server is installed, the apche2 directory is created in "/etc". In this folder, a default host file "000-default.conf" is created which can be used as a reference for creating our virtual host file. This file contains the configuration of our virtual hosts.
In this case, we will copy the default host file and name it as "abc.com.conf" and "xyz.com.conf".
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/abc.com.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/xyz.com.conf
Please edit the host file as below.
sudo vi /etc/apache2/sites-available/abc.com.conf
# ServerAdmin email@example.com
# ServerName abc.com
# ServerAlias www.abc.com
# DocumentRoot /var/www/abc.com/html
You can also add fields such as Error Log and Custom Log.
Edit the "xyz.com.conf" file in the same way we have edited the file above.
The next step is to enable the site with the help of the following command.
sudo a2ensite abc.com.conf
sudo a2ensite xyz.com.conf
Restart the Apache2 server
Please restart the web server to save the changes.
sudo service apache2 reload
You will notice that the sites will be displayed in the "/etc/apache2/sites-enabled" folder.
Local Host file Configuration
The last step is to map the IP address of the system to the websites in the local host file. In Ubuntu operating system, the local host file is "/etc/hosts".
Please open your browser and type the domain name of the websites. The web page that you have created will be displayed.