Ubuntu VPS

Apache Virtual Host Setup with Ubuntu 14.04

Written by Yogesh Koli

Apache Virtual Host Setup

This tutorial is answer to the question: How to setup domain on Virtual Private Server(VPS) using ubuntu?, meaning we can setup multiple domains with single IP address using Apache Virtual Host.

Note: I’m going to consider you have your VPS or local system is ready with Ubuntu to use this tutorial.

Let’s Get started.

Before start we need to have Apache installed on your Ubuntu Server, if you have’t installed Apache, please install by using following command:

Install Apache:

1. Create Directory

After getting Apache installed, we need to setup a directory for your project/website, this is the directory where we are going to store our website data or we called it as Production Code, so go ahead and use following command to create a directory.

You can replace ‘yourdomain.com’ to your real domain name, please take a note whatever domain your going to use the domain needs to have DNS forwarded to your server IP address. if you don’t have domain and your testing this tutorial on local system no worries you will get more info on this as well in the next steps.

2. Directory Permissions

We have to set permissions to the user along with the root user, follow below command to setup directory permissions, and also to all users to give read access.

Now we are ready to setup apache virtual host.

3. Virtual host file:

Apache provides default virtual file called 000-default.conf which is located at /etc/apache2/sites-available/ so the easy way to create new virtual file is just copy this default file with your domain name or whatever you want but it’s better to keep domain to identify files.

Use following lines to create duplicate/copy file of 000-default.conf

We have our file ready to configure, let’s do that in next step:

4. Configure Virtual host:

Edit the file we just created:

Change #ServerName www.example.com to ServerName yourdomain.com

If you need your site to be accessible with www add below lines after ServerName

Assign our website root directory which we had setup in first two steps

Finally yourdomain.com.conf file needs to look like this:

We are done with the configuration, let’s enable our virtual host:

As we have made changes in the configuration of apache we need to restart our apache to complete the configuration.

We are done,  just needs to add test page in the root directory so that we can see message/page or you can easily upload your website backup if you have already in place.

Let’s create index page to show message.

Add following content it the file

If you are using this tutorial to setup virtual domain on your local system, use following additional step to access your domain, you just simply needs to add records under host file.

We are all done you can test this setting on local system by using yourdomain.com.


If you find this tutorial useful, please share and let me know your feedback by using comment section below.

About the author

Yogesh Koli

Yogesh Koli is a software engineer & a Blogger lives in India. He's driven by an addiction to learning and a love for adventure. he has 5+ years of experience working with the front-end, back-end, web application development, and system design.


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of