Simple steps to setting up virtual host host on Ubuntu Server

Virtual host is a virtual environment over the top of your current web server to simulate a separate hosting environment. Using virtual host you can enable site specific features and keep your development environment totally separate from another one.

For tutorial you need to mod_rewrite enabled.

Step 1: setup hosts file

open /etc/hosts and add a virtual domain with a specific local IP.

Lets assume that our virtual domain name is “” and It will listen to the ip “″

so on /etc/hosts file we will add

now whenever you browse your browser will actually hit

Step2: configure virtual host with apache
Now goto /etc/apache2/sites-available and create a file named “

sudo touch ruzdi
sudo gedit /etc/apache2/sites-available/ruzdi

write the following contents inside. but please note to create the appropriate directory before linking your virtual host with that, for example we’ve create a folder named “/var/opt/ruzdi” and linked that directory as my document root in the following configuration file.

        DocumentRoot /opt/ruzdi
        <Directory /opt/ruzdi/>
                Options FollowSymLinks
                AllowOverride All


now create a symbolic link of this file to /etc/apache2/sites-enabled directory as “

sudo ln -s /etc/apache2/sites-available/ruzdi /etc/apache2/sites-enabled/ruzdi

**** here look directory location is /opt/ruzdi so you must create a directory named “ruzdi” on /opt location

Step 3: restart apache

simple, either one of the followings

sudo a2ensite ruzdi


sudo /etc/init.d/apache2 restart

now on your browser to http://

***This is post is similar Hasin Hyder blog post I just change a little. In my case on the hosts file port was not working so I removed it and I got everything all right.

source :


Hasin Hyder

  1. I want to install localhost in my ubuntu. I actually did install LAMP using ubuntu’s built-in repository. But something has gone wrong. When I hit localhost from my browser, it says couldn’t connect. I reinstalled LAMP several times but nothing happens.

    • Md. Ruzdi Islam
    • August 19th, 2010

    please check your apache port using command netstat -plntu

    if it is all right then check my post —- Simple steps to install Apache, MySql , PHP (LAMP) and PhpMyAdmin On Ubuntu Server (

  2. Your style is very unique compared to other folks I’ve read stuff from. Many thanks for posting when you’ve got the opportunity, Guess I will just bookmark
    this site.

  1. No trackbacks yet.

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: