Logo         Community
  Trog
Services
The Company
Community
Columns
Your Account
Contact Us
 
 
Getting More Out Of Apache (part 1)
Learn to use server-side includes and Apache's virtual hosting features.

| Alpha And Beta |

The keys to name-based virtual hosting are the appropriately-named NameVirtualHost and <VirtualHost> directives in the "httpd.conf" configuration file; these directives are used to specify basic information for the "virtual host", such as server name and server root, administrator email address, and log file locations.

Let's consider a simple scenario - creating two virtual hosts on the domain "localhost" (your Linux box) for the Web sites "melonfire-alpha.com" and "melonfire-beta.com". With the new NameVirtualHost directive, this is simplicity itself - open up the "httpd.conf" file in your favourite text editor, look for the "Virtual Hosts" section, and add the following entry to it:


NameVirtualHost 127.0.0.1:80


The NameVirtualHost directive specifies the IP address of the server which will be used to resolve virtual host names.

With that out of the way, it's now time to begin adding the virtual host definitions themselves.


<VirtualHost 127.0.0.1>
    ServerAdmin webmaster@melonfire-alpha.com
    DocumentRoot /www/melonfire-alpha.com
    ServerName melonfire-alpha.com
    ErrorLog logs/melonfire-alpha.com-error_log
    CustomLog logs/melonfire-alpha.com-access_log common
</VirtualHost>


Let's dissect this a little.

The first line


<VirtualHost 127.0.0.1>


specifies the IP address of the virtual host. Very simply, this is the IP address of the machine that holds the Web pages you plan to display. In the example above, the machine is "localhost", which traditionally has the IP address 127.0.0.1

The second line


ServerAdmin webmaster@melonfire-alpha.com


specifies the email address of the administrator for this virtual host.

The third and fourth lines


DocumentRoot /www/melonfire-alpha.com
ServerName melonfire-alpha.com


are probably the most important - they specify the domain name for the virtual host, and the physical location of the Web pages for that domain on the hard drive. Both these lines are crucial to ensuring that the correct Web page appears when the domain is accessed by a client browser.

Finally, the remaining two lines


ErrorLog logs/melonfire-alpha.com-error_log
CustomLog logs/melonfire-alpha.com-access_log common


specify the files to which server activity is to be logged. You can log server visits and server errors to separate files for each of your virtual hosts, or put it all into the common log files (the default option).

You can also add other Apache directives to this virtual host entry. Once you're done, close the entry with a


</VirtualHost>


tag.


How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!


previous page more like this  print this article  next page
 
Search...
 
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
more...
 
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
more...
 
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
more...
 
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
more...
 
In cut!...
American Chai
The Core
Possession
more...
 
Find out how you can use this article on your own Web site!


Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback