In this tutorial we will cover the steps needed to set up Apache virtual hosts on your CentOS 6.4, Debian or Ubuntu platform.

Requirements

  • CentOS 6.4, Debian or Ubuntu installed on your computer/server
  • SSH access (Command line access to the server)
  • root privileges
  • Basic skills for working on a Linux environment
  • Apache HTTP service

More than one separate websites can be hosted on one server using Apache virtual hosts. You can have few domain names pointed to the server's IP address and they will display different content depending on the Apache virtual host configuration and the web root folder set for the corresponding domain.

Create new web root folder

Let's create new folder called yourdomain.com inside the default Apache

CentOS 6.4:

sudo mkdir /var/www/html/yourdomain.com

Debian/Ubuntu:

Configure new Apache virtual host

We will make it default web root folder for the virtual host configuration:

CentOS 6.4:

Open the Apache configuration file and add the following lines at the end:

The important variables are:

DocumentRoot - represents the default web root folder where your website files should be placed.
ServerName – represents the domain name assigned to the virtual host
ServerAlias – you can place more than one domain name (aliases) which you want to be assigned to that virtual host

Debian/Ubuntu:

Create the following file which will contain the virtual host configuration:

When ready save the file and copy it to:

When ready save the file and restart the Apache service.

CentOS 6.4

Debian/Ubuntu:

Test the configuration

In case that yourdomain.com is pointed to the server's IP address you should be able to access the content placed inside the web root folder set inside the virtual host:

An easy way to find your server's IP address is to execute the following command: