How To Set Up Apache Virtual Host on Ubuntu

Apache web server is the most common and popular in web arena. It has an awesome feature of customization and running websites using virtualhosts.

In this article we will know how to setup virtualhost on apache on Ubuntu(14.04 currently i am using). We will setup “” which will actually point to “/home/<username>/sites/”

Before we start we assume you have root access, if necessary. <username> is basically your system user directory.

Step 1: First create a directory where you put all your source code under your home directory(most common place)

sudo mkdir /home/&lt;username&gt;/sites/

Add an index.html(with some content) file under
Step 2: Create a new virtualhost file copying existing file under directory “/etc/apache2/sites-available”

cd /etc/apache2/sites-available
cp 000-default.conf

Set at-least “ServerName” and “DocumentRoot” variable as below

 DocumentRoot /home/&lt;username&gt;/sites/

Step 3: Add a host entry into your host file locate under “/etc/hosts”


sudo vim /etc/hosts

add a line as below

Step 4: Now enable VitrualHost using below command and restart apache

 sudo a2ensite
sudo apachectl restart

Step 5: Open your web browser and hit the url

In case if you get message like “You don’t have permission to access / on this server. “, Please ensure that “” directory permission is set to 0777. Grant the required permission if necessary.


2 thoughts on “How To Set Up Apache Virtual Host on Ubuntu

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s