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 “ruzdi.com” and It will listen to the ip “127.0.0.2″

so on /etc/hosts file we will add

127.0.0.2 ruzdi.com

now whenever you browse http://ruzdi.com your browser will actually hit http://127.0.0.2

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

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.



<VirtualHost 127.0.0.2:80>
        ServerName  ruzdi.com
        ServerAlias  ruzdi.com
        ServerAdmin admin@ruzdi.com
        DocumentRoot /opt/ruzdi
        <Directory /opt/ruzdi/>
                Options FollowSymLinks
                AllowOverride All
        </Directory>

</VirtualHost>

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

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

And

sudo /etc/init.d/apache2 restart

now on your browser to http:// ruzdi.com

***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 :

Apache

Hasin Hyder

Advertisements
  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 (https://ruzdi.wordpress.com/2010/08/17/simple-steps-to-install-mysql-apache-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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: