How To Set Up Apache2 Virtual Hosts on Ubuntu 14.04

Introduction

On this topic we will cover the basics of how to add another domain to your VPS or Dedicated Server. As an owner of server it is very possible for you to add another domain to be hosted on that server.

Step 1: Install Apache2.

As start you can install your Apache2 on your Ubuntu. Of cource if you have your Apache2 installed already you can skip this step. The installation of apache2 can be achieved like this.

$ sudo apt-get update
$ sudo apt-get install apache2

Step 2: Create the Virtual Host

In Apache on Ubuntu all virtual host configuration files are stored under /etc/apache2/sites-available/ directory. To create a new virutal host you must run the following command:

nano /etc/apache2/sites-available/new-domain.com.conf

In this example we are adding domain new-domain.com. When you create the configuration file for the new domain do not forget to add .conf !

When you execute the command shown above you will open new blank document, inside it you must add this:

<VirtualHost *:80>
     ServerAdmin [email protected]
     ServerName new-domain.com
     ServerAlias www.new-domain.com
     DocumentRoot /var/www/html/new-domain.com
         <Directory "/var/www/html/new-domain.com">
                AllowOverride All
        </Directory>
</VirtualHost>

Do not forget to replace new-domain.com with your domain!

 

Step 3: Create the Virtual Host directory

Now we have to create the directory from where your domain will load the files for your website. As you can see in the above configuration the files are loaded from /var/www/html/new-domain.com . So we have to create the directory and give it the needed permissions.

 

mkdir /var/www/html/new-domain.com
chown www-data:www-data /var/www/html/new-domain.com

Step 4: Enable the Virtual Host

We are almost ready! Now we have to enable our new Virtual Host in order to make it available. For Apache2 in Ubuntu you can enable the new Virtual Host with the following command:

sudo a2ensite new-domain.com

Congratulations, we have enabled our first Virtual Host. At last we have to reload the Apache2 configuration to see the end result. To reload the Apache2 configuration files run this command:

service apache2 reload

 

Congratulations! We are ready!

Now your new domain new-domain.com is up and running. In order to add another domain just repeat the following guide and that's it. Here at VivasHost your Virtual Private Server you have unlimited domains per VPS.

Enjoy!

Share this post

Comments (0)

    There are no comments to this topic yet.


To post comments you must have account with VivasHost! To create an Account you must purchase any service you want.

Take a look at our VPS - Virtual Private Servers or our Dedicated Servers.