Hosting your websites

This article will help you to setup the hosts, in case you want to run multiple websites on your VPS. This is similar to setting up a shared server that hosts multiple websites, using a single shared IP Address.

Note

This documentation assumes you've already installed the LAMP stack on your VPS. If you haven't done that yet, refer to the LAMP installation guide.

Ensure that you are connected to the server using an SSH client as a root user.

Website management becomes easier through cPanel or Plesk. If you have installed any of these panels, you need not follow this documentation.

Hosts Setup

The process to host a single website is different from hosting multiple sites.

To Host a Single Website

If you want to host only one domain name in the VPS, then all you need to do is point your domain name to the IP Address of the VPS. This can be done by simply adding an A record for the domain name from the DNS interface of the VPS.

By default, the document root of your server is /var/www/html. You can upload the contents of your site in this directory. The website can also be accessed using the IP Address of the VPS.

To Host Multiple Websites

If you want to host multiple domain names in the same VPS, then you would be required to create a virtual host entry in your Apache configuration file. Refer to the steps mentioned
below.

Assume you want to host the websites for domain names domain1.com and domain2.com. You'll first have to create directories for each website under /var/www/html. You can create the directories from Plesk Power Panel's - File Manager or via SSH. The steps given below are using the Command Line Interface.

Navigate to the directory /var/www/html.

cd /var/www/html

Create the directories for each website.

mkdir domain1.com

The directories will be created as below.

Open the Apache configuration file by using the command:

vi /etc/httpd/conf/httpd.conf

Scroll down to the end of this file, uncomment the lines and add your domain names as shown below.

The various paramaters in Name based Virtual Hosting are:

NameVirtualHost: Designates an IP address for Name based Virtual Hosting

<VirtualHost>: Contains directives that apply only to a specific hostname or IP Address

ServerAdmin: Email address that the Server includes in error messages sent to the client

DocumentRoot: This directive sets the directory from which httpd will serve files for this host

ServerName: Used to uniquely identify the Virtual Host; FQDN (Fully Qualified Domain Name) format to be used

ServerAlias: This directive is used to set the alternate names for the host