Steps by Steps How to Configure – Virtual Hosting using Apache2 on Ubuntu 11.10 Oneiric

Let have an introduction on some term related to Apache, Virtual Hosting.

What is Apache?

The Apache HTTP Server commonly referred to as Apache, is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone. Apache was the first viable alternative to the Netscape Communications Corporation web server (currently named Oracle iPlanet Web Server), and since has evolved to rival other web servers in terms of functionality and performance. Typically Apache is run on a Unix-like operating system.

What is Virtual Hosting on Apache2?

The term Virtual Host refers to the practice of running more than one web site (such as http://www.company1.com and http://www.company2.com) 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. 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.

Steps by Steps How to Configure – Virtual Hosting using Apach2 on Ubuntu 11.10 Oneiric

Now firstly you need to install Apach2 server on your machine, if install OK but if not than type

$sudo apt-get install apache2-utils apache2-common

After installation of Apache2, let’s open main configuration file from > > > /etc/apache2/apache2.conf

Now search for line Include /etc/apache2/sites-enabled/[^.#]*

This mean that when starting apache, it will look for files in /etc/apache2/sites-enabled/.

Let’s go there and see what is in: –

$cd /etc/apache2/sites-enabled/

$ls –l total 1
lrwxrwxrwx 1 root root 36 2011-12-01 15:45 000-default -> /etc/apache2/sites-available/default

Now open /etc/apache2/sites-available and create a new configuration file like this

$sudo vim test.com.conf and add following lines.

<VirtualHost dev.example.com>
ServerAdmin webmaster@localhost
ServerAlias http://www.myserver.com
DocumentRoot /home/myuser/public_html/example.com
ScriptAlias /awstats/ /usr/lib/cgi-bin/
</VirtualHost>

Note: – In above script

  • VirtualHost > > > enter your host details
  • ServerAdmin > > > enter your login details
  • ServerAlias > > > enter server details
  • DocumentRoot > > > enter your source path of directory

Now, go to sites-enabled and create link of the file that we just create > > >

$cd /etc/apache2/sites-enabled/

$sudo ln -s /etc/apache2/sites-available/ test.com.conf test.com.conf

Now edit your hosts file

$vim /etc/hosts

127.0.0.1 localhost.localdomain localhost test.com www. test.com

Now, reload your apache server

sudo /etc/init.d/apache2 reload

Violaaaa… apache2 is configured….

Test your configuration > > >

http://localhost

Leave a comment