linux poison RSS
linux poison Email

Adding Virtual Hosts in Apache2 under Ubuntu

The term Virtual Host refers to the practice of running more than one web site (such as and on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user.

Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts.

Following are the simple steps for creating/adding virtual hosts in Apache2 under Ubuntu:

Steps #1:
First create the directory structure for holding the webpages and logs for your virtual hosts:
sudo mkdir /var/www/foo
sudo mkdir /var/www/goo
sudo mkdir /var/log/apache2/foo
sudo mkdir /var/log/apache2/goo
Steps #2:Add a proper host entry for site foo and site goo into your /etc/hosts file: vi /etc/hosts    foo    goo
Steps #3:
Now, go and create the vhosts file for site foo and goo: vi /etc/apache2/sites-available/foo and add the required contents as shown below:
<VirtualHost *:80>
        ServerAdmin foo-webmaster@localhost
        ServerName foo
        DocumentRoot /var/www/foo
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        <Directory /var/www/foo/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all

        ErrorLog /var/log/apache2/foo/error.log
        LogLevel warn
        CustomLog /var/log/apache2/foo/access.log combined

Similarly  create the /etc/apache2/sites-available/foo file for goo site

Steps #4:
Type following command to enable site foo and goo:
sudo a2ensite foo
sudo a2ensite goo
After this, restart/reload your apache server using command
sudo service apache reload
Finally, after successful apache reload/restart you should able to navigate to site http://foo and http://goo using any browser.


Post a Comment

Related Posts with Thumbnails