Wednesday, September 7, 2016

create multiple users with single command

create multiple users using shell script, if you get an requirement to create multiple users you have to spend lot of time but here sharing script which will execute in a minute and create number of users.
#!/bin/bash
## Purpose: Creating Multiple users in a single attempt
if [ "$#" = 0 ]; then
 echo "Usage: /scripts/createusers.sh file"
else if [ -f "$1" ]; then
 for i in `cat $1`; do useradd -s /bin/bash $i; done
for y in `cat $1`; do echo -e "password\npassword" | passwd $y; done
for z in `cat $1`; do cat /etc/passwd |grep $z; done
else echo "$1 not found"
fi
fi
Create Script file for create multiple users
[root@server scripts]# mkdir /scripts/
[root@server scripts]# vim /scripts/createusers.sh
PASTE above script here
:wq! (Save & Exit)
Change the permission script file
[root@server scripts]# chmod u+x /scripts/createuser.sh
Create a file with users list and execute
[root@server scripts]# vim file
harry
champu
john
[root@server scripts]# sh /scripts/createusers.sh file
default password for created users is password

Tuesday, August 30, 2016

Install php 5.4 on CentOS 6 with yum command

Install stomp via pecl on

pecl install stomp

php -m |grep -i stomp
Stomp

----------------------------------------------------------------------------------------------------------

In this post we will install php 5.4 on CentOS 6 with yum command . In available default repo of CentOS, we will get the php 5.3 version. Some PHP developers uses the PHP 5.4 version for application, hence we need PHP 5.4 to be installed on CentOS 6.x .

It is known that in CentOS 6 series versions, we can not get the PHP 5.4 version from default yum repo .
To install php 5.4 on CentOS 6.x, we will use the SCL repo. In terms of SoftwareCollections.org (SCL), “Software Collections give you the power to build, install, and use multiple versions of software on the same system, without affecting system-wide installed packages.”
Lets start the installation of PHP 5.4 .
Step 1. Install SCL repo only by hitting below given command.
yum install centos-release-SCL
Step 2. Install php 5.4 version on system now.
yum install php54
To install specific package, package name should be known. Hence, to get the list of available package list from SCL repo run below given command.
yum list|grep php
Step 3. Activate the PHP 5.4 on system.
NOTE: If you run below given command directly from terminal then on next login you will not find PHP 5.4 path.
source /opt/rh/php54/enable
Basically the above command, make PHP 5.4 executable path and environment available to current login user.
To make PHP 5.4 available to all user , we have to add line source /opt/rh/php54/enable inside file called /etc/profile. Now activate without logout by running command.
source /etc/profile
Or in case, if you only want php 5.4 available to specific user then just only edit .bashrc or .bash_profile file from User’s home directory. And add line source /opt/rh/php54/enable .
Step 4. Now check the php version
php -v
Below given is reference from our system.
[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Nov 19 2014 08:05:17) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
[root@localhost ~]# 
IMPORTANT NOTE : The PHP 5.4 package actually installed in /opt/rh directory.

Install mcrypt PHP module 
# install EPEL with yum
yum -y install epel-release
# install php-mcrypt
yum -y install php-mcrypt

Try running the following commands:
wget http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-1.noarch.rpm
rpm -ivh epel-release-7-1.noarch.rpm
yum install --enablerepo="epel" php-mcrypt

wget http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-1.noarch.rpm

Monday, August 29, 2016

FTP Commands

Introduction

The following information is provided as a reference for the File Transfer Protocol (FTP) commands. This document describes a typical process for an interactive and automated, batch FTP session running on a PC with Windows/XP and connecting to a UNIX system. This process may vary slightly depending on the hardware and software configurations of the local and remote systems.


We have made a significant effort to ensure the documents and software technologies are correct and accurate. We reserve the right to make changes without notice at any time. The function delivered in this version is based upon the enhancement requests from a specific group of users. The intent is to provide changes as the need arises and in a timeframe that is dependent upon the availability of resources.

An Interactive FTP Session

To start an FTP interactive session type "ftp" from a DOS Command window.
C:\> ftp 
The DOS prompt should be replaced with the FTP prompt. The FTP program is now running on the local system. A connection (or session) to a remote system has not been established.
The help command or ? (question mark) may be executed without being attached to a remote system and will do a print (usually to the screen) of the FTP commands. The following is an example of an FTP Command to display the FTP Help information.
ftp help
The following is a typical result of the help command running on a PC with Windows.
Commands may be abbreviated. Commands are:
!           delete      literal     prompt      send
?           debug       ls          put         status
append      dir         mdelete     pwd         trace
ascii       disconnect  mdir        quit        type
bell        get         mget        quote       user
binary      glob        mkdir       recv        verbose
bye         hash        mls         remotehelp
cd          help        mput        rename
close       lcd         open        rmdir
ftp
The following FTP Command will perform the FTP OPEN (make the connection) and display the following messages.
ftp  open domain.name 
Connected to domain.name
220 antigonous FTP server ready.
User (domain.name:(none)): User-Name
331 Password required for user-name
Password: password
230 User user-name logged in.
ftp
The following FTP Command will change the directory on the remote system and display the following message.
ftp> cd /web
250 CWD command successful.
ftp
The following FTP Command will find out the pathname of the current directory on the remote system and display the information.
ftp> pwd
257 "/web" is the current directory.
ftp
The following FTP Command will set the file transfer mode to ASCII (this is the default for most FTP programs) and display the information.
ftp> ascii
200 Type set to A.
ftp
The following FTP Command will copy a file(using ASCII mode) from the local system to the remote system and display the information.
ftp> put d:\simoweb1\filename.txt
200 PORT command successful.
Opening ASCII mode data connection for filename.txt
226 Transfer complete
ftp
The following FTP Command will set the file transfer mode to BINARY (the binary mode transfers all eight bits per byte and must be used to transfer non-ASCII files). ) and display the information.
ftp> binary
200 Type set to I.
ftp
The following FTP Command will copy a file (using BINARY mode) from the local system to the remote system and display the information.
ftp> put d:\simoweb1\filename.zip
200 PORT command successful.
Opening BINARY mode data connection for filename.zip
226 Transfer complete
ftp
The following FTP Command will exit the FTP environment (same as "bye") and display the information.
ftp> quit
221 Goodbye.
When the preceding FTP Command is finished the DOS prompt will be displayed.
C:\>
The preceding is a typical process for an interactive FTP session running on a PC with Windows/XP or Windows/7 and connecting to a UNIX system. This process may vary slightly depending on the hardware and software configurations of the local and remote systems.

An Automated, Batch FTP Session

The following batch file (UPWIP001.BAT) will start an FTP session and pass the name of a text file (UPWIP001.TXT) to the FTP program. This text file will be processed by the FTP program and each of the statements in the text file will be processed in the sequence they appear.
@echo OFF
rem  * *******************************************************************
rem  *               FTPSAME1.CMD - a Windows Command File               *
rem  *         This program is provided by SimoTime Enterprises          *
rem  *           (C) Copyright 1987-2013 All Rights Reserved             *
rem  *             Web Site URL:   http://www.simotime.com               *
rem  *                   e-mail:   helpdesk@simotime.com                 *
rem  * *******************************************************************
echo *
echo * This batch and text file illustrate the use of FTP to upload an
echo * ASCII file and an EBCDIC or Binary file. The UPWIP001.BAT file
echo * references UPWIP001.TXT that contains...
echo *
echo *   user
echo *   password
echo *   cd /web
echo *   pwd
echo *   ascii
echo *   put d:\simoweb1\cbltxn01.htm
echo *   binary
echo *   put d:\simoweb1\cbltxn01.zip
echo *   quit
echo *
ftp -s:upwip001.txt www.simotime.com
The following is a listing of the contents of the text file (UPWIP001.TXT).
user
password
cd /web
pwd
ascii
put d:\simoweb1\cbltxn01.htm
binary
put d:\simoweb1\cbltxn01.zip
quit

An FTP Command List

The following is a summary of the commonly used FTP Commands.
CommandDescription
!Preceding a command with the exclamation point will cause the command to execute on the local system instead of the remote system.
?Request assistance or information about the FTP commands. This command does not require a connection to a remote system.
asciiSet the file transfer mode to ASCII (Note: this is the default mode for most FTP programs).
bellTurns bell mode on / off. This command does not require a connection to a remote system.
binarySet the file transfer mode to binary (Note: the binary mode transfers all eight bits per byte and must be used to transfer non-ASCII files).
byeExit the FTP environment (same as quit). This command does not require a connection to a remote system.
cdChange directory on the remote system.
closeTerminate a session with another system.
debugSets debugging on/off. This command does not require a connection to a remote system.
deleteDelete (remove) a file in the current remote directory (same as rm in UNIX).
dirLists the contents of the remote directory.The asterisk (*) and the question mark (?) may be used as wild cards.
getRemoteName LocalName
helpRequest a list of all available FTP commands. This command does not require a connection to a remote system.
lcdChange directory on your local system (same as CD in UNIX).
lsList the names of the files in the current remote directory.
mgetCopy multiple files from the remote system to the local system.
Note: You will be prompted for a "y/n" response before copying each file.
mkdirMake a new directory within the current remote directory.
mputCopy multiple files from the local system to the remote system. (Note: You will be prompted for a "y/n" response before copying each file).
openOpen a connection with another system.
putCopy a file from the local system to the remote system.
pwdFind out the pathname of the current directory on the remote system.
quitExit the FTP environment (same as "bye"). This command does not require a connection to a remote system.
rmdirRemove (delete) a directory in the current remote directory.
traceToggles packet tracing. This command does not require a connection to a remote system.
  A List of FTP Commands

FTP Command, DIR

The DIR command will list the contents of the remote directory.The asterisk (*) and the question mark (?) may be used as wild cards.
ParametersDescription
b*This will display all entries that start with the letter "b". For example, the following will be displayed.
bet, ben, bingo, born, boon, bipartisan, bandit, boy
b*n*This will display all entries that start with the letter "b" and have the letter "n" somewhere after the letter "b". For example, the following will be displayed.
ben, bingo, born, boon, bipartisan, bandit
The following will not be displayed.
bet, boy
b?nThis will display all entries that start with the letter "b", have the letter "n" in the 3rd position and have a three character name. For example, the following will be displayed.
ben
The following will not be displayed.
bet, bingo, born, boon, bipartisan, bandit, boy
b?n*This will display all entries that start with the letter "b" and have the letter "n" in the 3rd position. For example, the following will be displayed.
ben, bingo, bandit
The following will not be displayed.
bet, born, boon, bipartisan, boy
  A List of Parameters for the DIR FTP Command

An FTP Extended Command List

The following are additional commands that are used when tranferring files between an IBM Mainframe and a Windows or UNIX client system. Also, the following includes commands required when working with files containing variable length records.
CommandDescription
literalWill send an argument to the remote FTP Server. This statement is similar in purpose as the "QUOTE" statement.
locsiteLOCSITE This statement may be used at the mainframe for commands specific to the mainframe
quoteWill send an argument to the remote FTP Server. This statement is similar in purpose as the "LITERAL" statement.
siteThis parameter is used at the client system to transfer a function (via the LITERAL or QUOTE statement) to the host site. The following is a summary of the commonly used SITE/LOCSITE Commands.
  A List of Extended FTP Commands

LOCSITE, LITERAL and SITE

This SITE (via the literal or quote command) statement is used at the client system and the LOCSITE command is used at the host system. Both statements are used to transfer a function to the host site. The following is a summary of the commonly used SITE/LOCSITE Commands.
CommandDescription
BLKSIZEBLocKSIZE=nnnn where nnnn is the block size (BLKSIZE)
CYLINDERSCYlinders To indicate that space should be allocated in cylinders
DIRECTORYDIrectory=nnn where 'nnn' indicates the number of directory blocks to be allocated for the directory of a PDS
LRECLLRecl=nnn where nnn is the logical record length (LRECL)
PRIMARYPRImary=nnn where nnn indicates the number of primary space units (tracks or cylinders)
RDWRDW will cause each record of a variable length record to be preceded with a four byte Record Descriptor Word (RDW) and possible four byte Block Descriptor Word (BDW).
RECFMRECfm=format where format is: F, FA, FB, FBA, FBM, FM, U, V, VA, VB, VBA, VBM, or VBS
SECONDARYSECondary=nnn where nnn indicates the number of secondary space units (tracks or cylinders)
TRACKSTRacks To indicate that space should be allocated in tracks.
  Parameters used with the LOCSITE Extended FTP Commands
The following is an example of the LITERAL command and a GET command. The commands are executed at the client and will cause the RDW (Record Descriptor Word) to be included at the beginning of each record of a file with variable length records.
LITERAL SITE RDW
GET host-file-name client-file-name
The following is an example of the LOCSITE command and a PUT command. The commands are executed at the host and will cause the RDW (Record Descriptor Word) to be included at the beginning of each record of a file with variable length records.
LOCSITE RDW
PUT host-file-name client-file-name
The following is an example of the LOCSITE command for accessing tape files with variable length recoerds. The command is executed at the host and will cause the RDW (Record Descriptor Word)to be included at the beginning of each record of a file with variable length records.
LOCSITE RDW READTAPEFORMAT=V 
PUT host-file-name client-file-name

Friday, August 26, 2016

Different types of Computer Hard Disk Drive and its Connectors


A hard disk drive also called hard drive, hard disk or disk drive is a device used for storing and retrieving digital data or information. A hard disk is a stack of disk known as the platter. A single hard disk usually consists of several platters and each platter requires two read/write heads, one for each side and is attached to a single access arm. Data are recorded electromagnetically in a concentric circle such as the track on a disk.

A hard disk speed can vary from 4500rpm - 7200rpm for Parallel ATA and 10000rpm to 15000rpm for SCSI drive and Serial Attached SCSI (SAS). Hard drive with 10000rpm to 15000rpm is more expensive than lower rpm drives, this kind of HDD are used primarily on servers that are used for transaction processing databases, internet infrastructure such as email, web server that require intensive data processing and operate continuously. HDD that are running 10,000rpm to 15,000rpm has smaller platters to lessen the power requirements and therefore have lower capacity than desktop computer drives.

harddisk drive parts

  • actuator :
    Used to position the head arms to different tracks on the surface of the platter, actuator is used in changing from track to track the only operation on the hard disk that requires active movement. This mechanism of hard disk must works at extreme speed, with precise accuracy for the data to be read and write accurately on the platter.


Different types of Hard disk drive (HDD)



Parallel ATAParallel Advance Technology Attachment (PATA) drives are also known as Integrated Drive Electronics (IDE) developed by Western Digital under the name Integrated Drive Electronics (IDE)





Small Computer System Interface (SCSI) Hard driveSmall Computer System Interface or SCSI for short and can be pronounce as "skuzzy" are high performance storage drives. SCSI drives are commonly found in servers were real time performance or 24/7 operation is required. SCSI drive are much faster than the standard drive Parallel ATA (PATA) with 5400RPM - 7200RPM access time compared to 10000RPM - 15000RPM for SCSI. Revolution Per Minute "RPM" of hard drives is a measurement of how many complete revolutions a computer's hard drive makes in a single minute. Fast rotation speed of the spindle means high data transfer , the higher the RPM, the faster the data will be accessed

2.5 inch IDE DriveParallel Advance Technology Attachment (PATA) drives are also known as Integrated Drive Electronics (IDE) with 2.5 inch form factor. Due to its smaller size it is commonly used in notebook PCs, external storage, gaming consoles, and portable video players.



Serial ATA DriveSerial ATA was designed to replace the older parallel ATA (PATA). SATA offers several advantages over the older IDE drive such as reduced cable size reducing from 40 pins in IDE to 7 pins in SATA, native hot swapping and has faster data transfer through higher signaling rates.



Serial Attached SCSI (SAS)The Serial Attached SCSI (SAS) is a new generation serial communication protocol for devices designed to allow for much higher speed data transfers and is compatible with SATA. The serial transmission of data requires fewer connections and eliminates the SCSI bus and still uses the very capable SCSI protocol. SAS uses a mechanically identical data and power connector to standard 3.5-inch SATA1/SATA2 HDDs and many server-oriented SAS RAID controllers are also capable of addressing SATA hard drives. SATA drives can be attached to a SAS drive controller and they will work perfectly because they are compatible but not SAS drive connected to a SATA controller this configuration will not work.


URL Redirect and Virtual Hosting

URL Redirect

<VirtualHost *:80>
    ServerAdmin root@example.com
    DocumentRoot /usr/local/apache/httpdocs/
    ServerName hrms.example.com
    ServerAlias www.hrms.example.com
RewriteEngine On
Options +FollowSymlinks
 Redirect  /  http://10.10.10.2:81/login
</VirtualHost>


-----------------------------------------------------------------------------------------------------------


<VirtualHost *:80>
DocumentRoot /usr/local/apache/htdocs/example/redirection
ServerName www.example.com
ServerAlias example.com
ServerAdmin root@example.com
DirectoryIndex ip_redirect.php
<Directory /usr/local/apache/htdocs/example/redirection>
        AllowOverride All
        Order allow,deny
        Allow from all
        Options +Includes +ExecCGI -Indexes
</Directory>
CustomLog "|/usr/sbin/rotatelogs /usr/local/apachelogs/example.com_%Y-%m-%d.log 86400" combined 
ErrorLog /usr/local/apachelogs/example_error.log_%Y-%m-%d.log
</VirtualHost>


-------------------------------------------------------------------------------------------------------------


<VirtualHost *:80>
DocumentRoot /usr/local/apache/htdocs/example_doc
ServerName www.example.com
ServerAlias example.com
ServerAdmin root@example.com
DirectoryIndex index.php
<Directory /usr/local/apache/htdocs/example_doc>
        AllowOverride All
        Order allow,deny
        Allow from all
        Options +Includes +ExecCGI -Indexes
</Directory>
CustomLog "|/usr/sbin/rotatelogs /usr/local/apachelogs/example.com.log 86400" common
ErrorLog /usr/local/apachelogs/example.com_error.log
</VirtualHost>

Apache Virtual Host documentation ( IP-based and Name-based )

The term Virtual Host refers to the practice of running more than one web site (such as company1.example.com and company2.example.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 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.
Below is a list of documentation pages which explain all details of virtual host support in Apache HTTP Server:

Virtual Host Support


  • Name-based Virtual Hosts (More than one web site per IP address)
  • IP-based Virtual Hosts (An IP address for each web site)
  • Virtual Host examples for common setups
  • File Descriptor Limits (or, Too many log files)
  • Dynamically Configured Mass Virtual Hosting
  • In-Depth Discussion of Virtual Host Matching

Configuration directives


  • NameVirtualHost
  • <VirtualHost>
  • ServerName
  • ServerAlias
  • ServerPath
If you are trying to debug your virtual host configuration, you may find the Apache -S command line switch useful. That is, type the following command:
/usr/local/apache2/bin/httpd -S
This command will dump out a description of how Apache parsed the configuration file. Careful examination of the IP addresses and server names may help uncover configuration mistakes. (See the docs for the httpd program for other command line options)

Apache IP-based Virtual Host Support



What is IP-based virtual hosting

IP-based virtual hosting is a method to apply different directives based on the IP address and port a request is received on. Most commonly, this is used to serve different websites on different ports or interfaces.
In many cases, name-based virtual hosts are more convenient, because they allow many virtual hosts to share a single address/port. See Name-based vs. IP-based Virtual Hosts to help you decide.

System requirements

As the term IP-based indicates, the server must have a different IP address/port combination for each IP-based virtual host. This can be achieved by the machine having several physical network connections, or by use of virtual interfaces which are supported by most modern operating systems (see system documentation for details, these are frequently called "ip aliases", and the "ifconfig" command is most commonly used to set them up), and/or using multiple port numbers.
In the terminology of Apache HTTP Server, using a single IP address but multiple TCP ports, is also IP-based virtual hosting

How to set up Apache

There are two ways of configuring apache to support multiple hosts. Either by running a separate httpd daemon for each hostname, or by running a single daemon which supports all the virtual hosts.
Use multiple daemons when:
  • There are security partitioning issues, such as company1 does not want anyone at company2 to be able to read their data except via the web. In this case you would need two daemons, each running with different User, Group, Listen, and ServerRoot settings.
  • You can afford the memory and file descriptor requirements of listening to every IP alias on the machine. It's only possible to Listen to the "wildcard" address, or to specific addresses. So if you have a need to listen to a specific address for whatever reason, then you will need to listen to all specific addresses. (Although one httpd could listen to N-1 of the addresses, and another could listen to the remaining address.)
Use a single daemon when:
  • Sharing of the httpd configuration between virtual hosts is acceptable.
  • The machine services a large number of requests, and so the performance loss in running separate daemons may be significant.

Setting up multiple daemons

Create a separate httpd installation for each virtual host. For each installation, use the Listen directive in the configuration file to select which IP address (or virtual host) that daemon services. e.g.
Listen 192.168.0.1:80
It is recommended that you use an IP address instead of a hostname (see DNS caveats).

Setting up a single daemon with virtual hosts

For this case, a single httpd will service requests for the main server and all the virtual hosts. The VirtualHost directive in the configuration file is used to set the values of ServerAdmin, ServerName, DocumentRoot, ErrorLog and TransferLog or CustomLog configuration directives to different values for each virtual host. e.g.
<VirtualHost 192.168.0.1:80>
ServerAdmin webmaster@smallco.example.com
DocumentRoot /groups/smallco/www
ServerName smallco.example.com
ErrorLog /groups/smallco/logs/error_log
TransferLog /groups/smallco/logs/access_log
</VirtualHost>

<VirtualHost 192.168.0.2:80>
ServerAdmin webmaster@baygroup.example.org
DocumentRoot /groups/baygroup/www
ServerName baygroup.example.com
ErrorLog /groups/baygroup/logs/error_log
TransferLog /groups/baygroup/logs/access_log
</VirtualHost>
It is recommended that you use an IP address instead of a hostname in the <VirtualHost> directive (see DNS caveats).
Specific IP addresses or ports have precedence over their wildcard equivalents, and any virtual host that matches has precedence over the servers base configuration.
Almost any configuration directive can be put in the VirtualHost directive, with the exception of directives that control process creation and a few other directives. To find out if a directive can be used in the VirtualHost directive, check the Context using the directive index.
SuexecUserGroup may be used inside a VirtualHost directive if the suEXEC wrapper is used.
SECURITY: When specifying where to write log files, be aware of some security risks which are present if anyone other than the user that starts Apache has write access to the directory where they are written. See the security tips document for details.


Name-based Virtual Host Support



Name-based vs. IP-based Virtual Hosts

IP-based virtual hosts use the IP address of the connection to determine the correct virtual host to serve. Therefore you need to have a separate IP address for each host. With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers. Using this technique, many different hosts can share the same IP address.
Name-based virtual hosting is usually simpler, since you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames. Name-based virtual hosting also eases the demand for scarce IP addresses. Therefore you should use name-based virtual hosting unless you are using equipment that explicitly demands IP-based hosting. Historical reasons for IP-based virtual hosting based on client support are no longer applicable to a general-purpose web server, unless you are using a mod_ssl version without SNI support (standard in Apache releases since 2.2.12).

Using Name-based Virtual Hosts


To use name-based virtual hosting, you must designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHost directive. In the normal case where any and all IP addresses on the server should be used, you can use * as the argument toNameVirtualHost. If you're planning to use multiple ports (e.g. running SSL) you should add a Port to the argument, such as *:80. Note that mentioning an IP address in a NameVirtualHost directive does not automatically make the server listen to that IP address. See Setting which addresses and ports Apache uses for more details. In addition, any IP address specified here must be associated with a network interface on the server.
The next step is to create a <VirtualHost> block for each different host that you would like to serve. The argument to the <VirtualHost> directive must match a defined NameVirtualHost directive. (In this usual case, this will be "*:80"). Inside each <VirtualHost> block, you will need at minimum a ServerName directive to designate which host is served and a DocumentRoot directive to show where in the filesystem the content for that host lives.

Main host goes away

If you are adding virtual hosts to an existing web server, you must also create a <VirtualHost> block for the existing host. The ServerName andDocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.
For example, suppose that you are serving the domain www.domain.tld and you wish to add the virtual host www.otherdomain.tld, which points at the same IP address. Then you simply add the following to httpd.conf:
NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
You can alternatively specify an explicit IP address in place of the * in both the NameVirtualHost and <VirtualHost> directives. For example, you might want to do this in order to run some name-based virtual hosts on one IP address, and either IP-based, or another set of name-based virtual hosts on another address.
Many servers want to be accessible by more than one name. This is possible with the ServerAlias directive, placed inside the <VirtualHost> section. For example in the first <VirtualHost> block above, the ServerAlias directive indicates that the listed names are other names which people can use to see that same web site:
ServerAlias domain.tld *.domain.tld
then requests for all hosts in the domain.tld domain will be served by the www.domain.tld virtual host. The wildcard characters * and ? can be used to match names. Of course, you can't just make up names and place them in ServerName or ServerAlias. You must first have your DNS server properly configured to map those names to an IP address associated with your server.
The complete list of names in the VirtualHost directive are treated just like a (non wildcard) ServerAlias.
Finally, you can fine-tune the configuration of the virtual hosts by placing other directives inside the <VirtualHost> containers. Most directives can be placed in these containers and will then change the configuration only of the relevant virtual host. To find out if a particular directive is allowed, check the Context of the directive. Configuration directives set in the main server context (outside any <VirtualHost> container) will be used only if they are not overridden by the virtual host settings.
Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then it will look at each <VirtualHost>section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.
As a consequence, the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches theNameVirtualHost directive. If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a<VirtualHost> container and list it first in the configuration file.

Compatibility with Older Browsers

As mentioned earlier, there are some clients who do not send the required data for the name-based virtual hosts to work properly. These clients will always be sent the pages from the first virtual host listed for that IP address (the primary name-based virtual host).

How much older?

Please note that when we say older, we really do mean older. You are very unlikely to encounter one of these browsers in use today. All current versions of any browser send the Host header as required for name-based virtual hosts.
There is a possible workaround with the ServerPath directive, albeit a slightly cumbersome one:
Example configuration:
NameVirtualHost 111.22.33.44

<VirtualHost 111.22.33.44>
ServerName www.domain.tld
ServerPath /domain
DocumentRoot /web/domain
</VirtualHost>
What does this mean? It means that a request for any URI beginning with "/domain" will be served from the virtual host www.domain.tld. This means that the pages can be accessed as http://www.domain.tld/domain/ for all clients, although clients sending a Host: header can also access it as http://www.domain.tld/.
In order to make this work, put a link on your primary virtual host's page to http://www.domain.tld/domain/. Then, in the virtual host's pages, be sure to use either purely relative links (e.g., "file.html" or "../icons/image.gif") or links containing the prefacing /domain/ (e.g., "http://www.domain.tld/domain/misc/file.html" or "/domain/misc/file.html").
This requires a bit of discipline, but adherence to these guidelines will, for the most part, ensure that your pages will work with all browsers, new and old.