Setup APACHE Virtual Host Pada Ubuntu 12.04


About Virtual Hosts
Virtual Hosts are used to run more than one domain off of a single IP address. This is especially useful to people who need to run several sites off of one virtual private server. The sites display different information to the visitors, depending on with which the users accessed the site.

Set Up
The steps in this tutorial require the user to have root privileges.

apt-get install apache2

Step One— Create a New Directory
The first step in creating a virtual host is to a create a directory where we will keep the new website’s information.

This location will be your Document Root in the Apache virtual configuration file later on. By adding a -p to the line of code, the command automatically generates all the parents for the new directory
mkdir -p /var/www/

In this tutorial we will use as a placeholder for a correct domain name.

Step Two—Grant Permissions

chown -R $USER:$USER /var/www/
chmod -R 755 /var/www

Step Three— Create the Page

nano /var/www/

We can add some text to the file so we will have something to look at when the IP redirects to the virtual host.

    <h1>Success: You Have Set Up a Virtual Host</h1>

Save and Exit

Step Four—Create the New Virtual Host File

cp /etc/apache2/sites-available/default /etc/apache2/sites-available/

Step Five—Turn on Virtual Hosts

nano /etc/apache2/sites-available/

The first step is to insert a line for the ServerName under the ServerAdmin line.


If you want to make your site accessible from more than one name (for example, with www in the URL), you can include the alternate names in your virtual host file by adding a ServerAlias Line. The beginning of your virtual host file would then look like this:

<VirtualHost *:80>

The next step is to fill in the correct Document Root.

DocumentRoot /var/www/

Save and Exit.

The last step is to activate the host,


Step Six—Restart Apache

service apache2 restart

You may see an error along the lines of

Could not reliably determine the server's fully qualified domain name, using for ServerName

To Fix it, Edit file /etc/apache2/httpd.conf.  Insert Line :

ServerName localhost

Save dan Exit.  restart Apache again.

Optional Step Seven—Setting Up the Local Hosts

If you have pointed your domain name to your virtual private server’s IP address you can skip this step—you do not need to set up local hosts. Your virtual hosts should work. However, if want to try out your new virtual hosts without having to connect to an actual domain name, you can set up local hosts on your computer alone.

For this step, make sure you are on the computer itself, not your droplet.

nano /etc/hosts

Then insert line :       localhost

#Virtual Hosts

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

%d bloggers like this: