Apache VirtualHosts – HowTo

IMAG0652

I used to do this whenever I make a new PHP project. But I forget the steps often. This post will explain you how to add a new virtual host in apache.

1. Apache server installed (I’ve used XAMPP ) with php plugin enabled

2. Make a new folder in your computer. Ensure you have an index.html or index.php on that folder. I’ve my folder on C:\xampp\htdocs\market

3. Make the following steps on C:\xampp\apache\conf\extra\httpd-vhosts.CONF file. This will be the file to define your virtual hosts

Add the following lines at the end of this file.

#this is to access the standard xampp home page
NameVirtualHost localhost:80
<VirtualHost localhost>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
#ServerAlias http://www.dummy-host.localhost
#ErrorLog "logs/dummy-host.localhost-error.log"
#CustomLog "logs/dummy-host.localhost-access.log" combined
</VirtualHost>

#this is our virtual host grassfield.dev
NameVirtualHost grassfield.dev:80
<VirtualHost grassfield.dev>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs\market"
ServerName grassfield.dev
#ServerAlias http://www.grassfield.dev
#ErrorLog "logs/grassfield.dev-error.log"
#CustomLog "logs/grassfield.dev-access.log" combined
</VirtualHost>

4. Restart the apache service

5. Access http://localhost and http://grassfield.dev sites are rendered correctly on the browser. Sample file is attached in this post.

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/&gt;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
NameVirtualHost localhost:80
<VirtualHost localhost>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
#ServerAlias http://www.dummy-host.localhost
#ErrorLog "logs/dummy-host.localhost-error.log"
#CustomLog "logs/dummy-host.localhost-access.log" combined
</VirtualHost>
##<VirtualHost *:80>
##ServerAdmin postmaster@dummy-host2.localhost
##DocumentRoot "C:/xampp/htdocs/dummy-host2.localhost"
##ServerName dummy-host2.localhost
##ServerAlias http://www.dummy-host2.localhost
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log" combined
##</Virtual
NameVirtualHost grassfield.dev:80
<VirtualHost grassfield.dev>
ServerAdmin pandian@grassfield.org
DocumentRoot "C:\xampp\htdocs\market"
ServerName grassfield.dev
#ServerAlias http://www.grassfield.dev
#ErrorLog "logs/grassfield.dev-error.log"
#CustomLog "logs/grassfield.dev-access.log" combined
</VirtualHost>

The picture at the top don’t have any relations with this post 😉

Advertisements

Virtualization Terminologies – 1

VMware ESX server:

This is a popular virtualization solution from VMware.
Installs on a ‘bare metal’, allows multiple OSs and their applications to run in VMs.

Physical server/Virtual Host:

The Operating System running on a bare metal

Guests/Virtual Machines

Individual Operating Systems hosted by ESX or Virtual Host

VMKernel

An OS that runs directly on the ESX server host.

Resource Manager:

Partitions the physical resources of the underlying server
Uses proportional share mechanism to allocate CPU, memory and disk resources to VMs those are powered on
manages the reservations, limits of each VM

VMKernal Hardware Interface:

Hides the hardware differences from ESX server and guest users.
Enables hardware specific service delivery
Includes device drivers and Virtual Machine File System (VMFS)

Virtual Machine Monitor (VMM):

Responsible for virtualizing CPUs
When the VM is getting started, the control is transferred to VMM
Sets the system state