Apache Virtual host confguration in Linux (Ubuntu)

Some days ago I have posted how to configure apache virtual host in windows. You can find it here. Now I will describe how to configure virtual host in Linux. It’s all most same. This will take few steps

1. Locating the config file:

You first work is to find the config file.

  1. In most setups, apache takes up residence in /usr/local/apache. If so, chances are your configuration file is /usr/local/apache/conf/httpd.conf. I am using Ubuntu (Gutsy Gibbon) and I have found it here.
  2. If not then let us find it.
$ find / -type f -name httpd
./usr/local/apache/bin/httpd

2 . Now configure the httpd.conf

The virtual host config starts with, the virtual host tag. Anything between the opening (<VirtualHost *>) and the closing (</VirtualHost>) tags is the configuration.

I am going to setup the test.local .

# The localhost in the VirtualHost tag, tells apache that any request with test.local from localhost

NameVirtualHost localhost

<VirtualHost localhost>

# This should be self-explanatory, the name and port under which the server

# identifies itself. If the port is 80 (default) it is not necessary to include it.

# If this is not set to a valid DNS name, server-side redirects will fail.

ServerName test.local

#

ServerAdmin admin@test.local

# Place where the documents for this domain live. replace it by your own

DocumentRoot /var/www/test

</VirtualHost>

This is the basic setup.

3. Last change

Obviously, if you typed http://test.local in your browser, it would not be found by your Internet provider’s DNS server. We’re next going to edit another file to work around that. The second file you need to edit is called hosts, with no file extension. It will enable you to enter specific addresses for specific domains instead of using a DNS lookup. The normal location for this file is:

/etc/hosts

Just go to the bottom of the file, below all the comments and any existing entries and add the following two lines:

127.0.0.1 test.local

That’s all you need to do there. Save and close the hosts file.

Lastly :

You’re almost done! The only remaining thing you need to do is to re-start the Apache server. You need to do this because Apache only reads the configuration file when it first starts up.

Can you browse http://test.local???

4 Comments »

  1. hasin said

    cool!

  2. Tapos said

    Thank you Hasin Bhai, reading my post.

  3. sinzmanual said

    thx.will try to my server using zoneedit DNS.

  4. erick said

    Still learning in ubuntu.
    Thanks for info.Nice info here !

RSS feed for comments on this post · TrackBack URI

Leave a Comment