KABIR If Apache Server 2 can do it, you can do it too . . . Updated for the latest Apache release and packed with real-world examples, this all-in-one reference shows you step by step how to take full advantage of Apache Server — and create a Web site that’s fast, secure, and easy to maintain. Bestselling author Mohammed Kabir offers complete guidance on every detail of Apache implementation, from installation and configuration to Web site administration, server-side applications, security, and performance tuning. Whether you’re a novice Web administrator or an Apache veteran, this is the only book you need to harness the power of the world’s leading Web server. Shelving Category: Networking/Internet Reader Level: Beginning to Advanced System Requirements: Pentium-class PC running Windows 9X/2000/Me and XP; Linux; or Unix; CD-ROM drive. See About the CD Appendix for details. ISBN 0-7645-4821-2 $49.99 USA $74.99 Canada £39.99 UK incl. VAT Apache Server 2 Configure Apache Server for a Linux/Unix or Win32 system Leverage Apache using SSI, CGI, PHP, Perl, and Java servlets Secure your site using SSL, certificate- signing services, and other tools A pache Server 2 Mohammed J. Kabir “Kabir has done it again! The Apache Server 2 Bible is an invaluable reference for both beginning and experienced administrators.” — Elizabeth Zinkann, Sys Admin Magazine Contributing Editor and Review Columnist ,!7IA7G4-feicbf!:p;o;t;T;T Apache, PHP, Perl, and more on CD-ROM! BONUS CD-ROM! Apache, PHP, Perl, Tomcat, MySQL, and more www.hungryminds.com 100% ONE HUNDRED PERCENT COMPREHENSIVE AUTHORITATIVE WHAT YOU NEED ONE HUNDRED PERCENT CD-ROM features: • Apache Web Server • PHP, Perl, mod_ perl, MySQL, and other open source tools for dynamic Web pages • OpenSSL and ApacheSSL security software • Plus all sample code from the book and more A pache Server 2 Bible Author of Red Hat Linux Server *85555-AHHDHj 100% COMPREHENSIVE Apache Server 2 Inside, You’ll Find Complete Coverage of Apache Server 2 • Master source compilation and binary installation • Customize Apache to match your system • Create and manage virtual Web sites with Apache • Monitor server performance with a log analyzer package • Set up an Apache-based proxy server • Create a Web cycle involving development, testing, and production systems • Turbocharge Web interactivity with FastCGI, PHP, Perl, and Java servlets • Secure Apache with Apache SSL and your own Certificate Authority • Configure Apache for Win32 systems • Create a high-availability Web network using Apache Create an interactive Web site using JSP servelets, CGI, and mod_perl scripts Request Load Balancer Load Balancer Switch Front-end Network 207.183.233.17 207.183.233.17 www.[1-N].domain.com Load Balancer Web Server Farm Switch Application Server Farm Database Server Farm 192.168.1.1 Load Balancer Back-end Network 192.168 .1.1 Configure your Web servers for reliability and security 4821-2 cover 2/6/02 9:20 AM Page 1 Apache Server 2 Bible a4821-2 FM.F 2/22/02 10:09 AM Page i a4821-2 FM.F 2/22/02 10:09 AM Page ii Apache Server 2 Bible Mohammed J. Kabir Best-Selling Books • Digital Downloads • e-Books • Answer Networks • e-Newsletters • Branded Web Sites • e-Learning New York, NY✦ Cleveland, OH ✦ Indianapolis, IN a4821-2 FM.F 2/22/02 10:09 AM Page iii LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES. Apache Server 2 Bible Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 www.hungryminds.com Copyright © 2002 Hungry Minds, Inc. All rights reserved. No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher. Library of Congress Control Number: 2001092889 ISBN: 0-7645-4821-2 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 1B/RT/QT/QS/IN Distributed in the United States by Hungry Minds, Inc. Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria, and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc. for Micronesia; by Chips Computadoras S.A. de C.V. for Mexico; by Editorial Norma de Panama S.A. for Panama; by American Bookshops for Finland. For general information on Hungry Minds’ products and services please contact our Customer Care department within the U.S. at 800-762-2974, outside the U.S. at 317-572-3993 or fax 317-572-4002. For sales inquiries and reseller information, including discounts, premium and bulk quantity sales, and foreign-language translations, please contact our Customer Care department at 800-434-3422, fax 317-572-4002 or write to Hungry Minds, Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256. For information on licensing foreign or domestic rights, please contact our Sub-Rights Customer Care department at 212-884-5000. For information on using Hungry Minds’ products and services in the classroom or for ordering examination copies, please contact our Educational Sales department at 800-434-2086 or fax 317-572-4005. For press review copies, author interviews, or other publicity information, please contact our Public Relations department at 317-572-3168 or fax 317-572-4168. For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470. Trademarks: Bible and Hungry Minds are trademarks or registered trademarks of Hungry Minds, Inc. All other trademarks are the property of their respective owners. Hungry Minds, Inc., is not associated with any product or vendor mentioned in this book. is a trademark of Hungry Minds, Inc. a4821-2 FM.F 2/22/02 10:09 AM Page iv Credits Acquisitions Editor Terri Varveris Project Editor James H. Russell Technical Editor Gregory W. Stephens Copy Editor Richard H. Adin Editorial Managers Kyle Looper Ami Frank Sullivan Vice President & Executive Group Publisher Richard Swadley Vice President & Group Publisher Bob Ipsen Editorial Director Mary Bednarek Project Coordinator Regina Snyder Graphics and Production Specialists Beth Brooks Melanie DesJardins Joyce Haughey Betty Schulte Jeremey Unger Quality Control Technicians Laura Albert John Greenough Andy Hollandbeck Angel Perez Media Development Specialist Travis Silvers Illustrator Kate Shaw Proofreading and Indexing TECHBOOKS Production Services Cover Image Kate Shaw a4821-2 FM.F 2/22/02 10:09 AM Page v About the Author Mohammed Kabir is the founder and CEO of Evoknow, Inc. His company specializes in CRM software development. When he is not busy managing software projects or writing books, he enjoys traveling. Kabir studied computer engineering at California State University, Sacramento. He can be reached at kabir@evoknow.com. a4821-2 FM.F 2/22/02 10:09 AM Page vi To the memory of my mother, Nazma Bathen. a4821-2 FM.F 2/22/02 10:09 AM Page vii a4821-2 FM.F 2/22/02 10:09 AM Page viii Preface W elcome to Apache Server 2.0. Chances are that you already have heard about Apache server. In fact, more than 60 percent of all Web administra- tors use Apache. Apache is the most powerful, open-source, Web-server platform in the world. As a practicing Web developer, researcher, and administrator, I find Apache to be the perfect fit for most Web sites. Apache 2.0 is a major revision of Apache server. Apache Group originally created a highly configurable Web server in the first ver- sion, which became popular very fast; in version 2, Apache Group focused on scala- bility, reliability, and performance. Major code revisions were done to create a very scalable Apache architecture. Today, Apache stands tall as the most widely used Web platform. Every day an increasing number of corporations accept this open-source marvel into their IT infrastructure. Many large IT companies, such as IBM, have embraced Apache in their product offerings. The future of Apache looks great. Whether you’re new to Apache or are already a practicing Apache administrator, now is the perfect time to get started with Apache 2.0. This book will help you do just that. How This Book Is Organized The book has six parts. Very short descriptions of each part follow. Part I: Getting Started With a brief introduction to the world’s number one Web server, in this part I guide you through the process of obtaining and compiling Apache. I show you how to get Apache up and running with minimal changes to the default configuration files so that you can get Apache up and running on your system as quickly as possible. This part ends with complete references to the Apache core directives and standard modules so that you can get ready for serious Apache administration tasks. a4821-2 FM.F 2/22/02 10:09 AM Page ix [...]... 10 5 10 6 10 6 10 7 10 9 10 9 11 0 1 12 11 6 11 7 11 8 12 2 12 4 12 4 12 8 12 8 13 0 13 0 13 1 13 7 13 8 13 8 a4 8 21 -2 FM.F 2/ 22/ 02 10 :09 AM Page xxi Contents mod_expires mod_cern_meta Server Information and Logging Modules mod_log_config mod_status mod_info ... 26 5 26 6 26 6 26 7 26 8 26 9 26 9 27 0 27 0 27 1 27 1 27 2 27 2 27 3 27 3 27 3 27 4 27 4 27 4 27 5 27 5 27 6 27 6 27 8 27 8 27 8 28 1 28 2 28 3 Chapter 11 : Running Perfect Web Sites 29 3 What is a Web Development Cycle? Putting the Web Cycle into Action Setting up for the Web... 10 1 1 02 1 02 1 02 1 02 1 02 1 02 1 02 1 02 10 3 10 3 10 3 10 3 10 3 10 3 10 3 10 3 10 4 10 4 10 4 10 4 10 4 10 4 Chapter 5: Apache Modules 10 5 An Overview of the Modules Environment-Related Modules mod_env mod_setenvif ... 21 3 21 4 21 6 22 1 22 2 22 3 22 3 22 4 22 4 22 7 22 8 23 0 23 2 23 4 23 4 23 4 23 6 Chapter 9: Rewriting Your URLs 23 9 The URL-Rewriting Engine for Apache RewriteEngine RewriteOptions RewriteRule ... URLs 23 9 24 2 24 3 24 3 24 5 24 8 24 9 24 9 25 0 25 0 25 1 25 1 25 2 25 3 25 6 25 7 25 9 25 9 26 1 a4 8 21 -2 FM.F 2/ 22/ 02 10 :09 AM Page xxiii Contents Content Handling Adding backward compatibility in URLs Creating browser-matched content URLs Creating... Combining Authentication and Authorization 18 1 1 82 18 4 18 4 18 6 18 7 18 8 19 0 19 0 1 92 1 92 19 5 xxi a4 8 21 -2 FM.F xxii 2/ 22/ 02 10 :09 AM Page xxii Apache Server 2 Bible Authenticating with a Relational Database Using MySQL database server for authentication Using other databases for user authentication Managing Users and Groups in Any... 10 :10 AM Page 4 Part I ✦ Getting Started Table 1- 1 Top Server Statistics by Netcraft Server Nov 20 01 Percent Dec 20 01 Percent Apache 775 027 5 61. 88 8588 323 63.34 Microsoft IIS 330 720 7 26 .40 3609 428 26 . 62 iPlanet 4 319 35 3.45 383078 2. 83 Zeus 17 40 52 3.45 1 723 52 1 .27 Apache Rocks On What Apache has accomplished is simply amazing! Who knew that an open source Web server could consistently beat two major commercial... the Apache code directives and the many popular modules that make Apache the most configurable Web server on the planet A ✦ ✦ ✦ ✦ In This Part Chapter 1 Apache: The Number One Web Server Chapter 2 Obtaining and Installing Apache Chapter 3 Getting Apache Up and Running Chapter 4 The Core and MPM Directives Chapter 5 The Apache Modules ✦ ✦ ✦ ✦ b4 8 21 -2 PO1.F 2/ 22/ 02 10 :09 AM Page 2 c4 8 21 -2 ch 01. F 2/ 22/ 02. .. 3 21 323 323 326 327 328 328 329 330 335 335 336 338 3 41 3 42 3 42 370 370 3 71 3 71 3 71 3 71 373 374 a4 8 21 -2 FM.F 2/ 22/ 02 10 :09 AM Page xxv Contents Chapter 13 : Server Side Includes (SSI) 377 What Is a Server Side Include? Configuring Apache for SSI Enabling SSI for an entire directory Enabling SSI... Administration 13 9 14 1 14 3 14 3 14 3 14 3 14 3 14 4 14 4 14 5 14 8 14 9 15 1 15 1 1 52 15 5 15 5 15 7 Chapter 6: Hosting Virtual Web Sites 15 9 Understanding Apache s Virtual Hosting Capabilities Setting Up a Virtual Host Name-based virtual hosts IP-based virtual hosts Multiple main servers as virtual hosts . Web servers for reliability and security 4 8 21 -2 cover 2/ 6/ 02 9 :20 AM Page 1 Apache Server 2 Bible a4 8 21 -2 FM.F 2/ 22/ 02 10 :09 AM Page i a4 8 21 -2 FM.F 2/ 22/ 02 10 :09 AM Page ii Apache Server 2 Bible Mohammed. kabir@evoknow.com. a4 8 21 -2 FM.F 2/ 22/ 02 10 :09 AM Page vi To the memory of my mother, Nazma Bathen. a4 8 21 -2 FM.F 2/ 22/ 02 10 :09 AM Page vii a4 8 21 -2 FM.F 2/ 22/ 02 10 :09 AM Page viii Preface W elcome to Apache Server 2. 0 Network 20 7 .18 3 .23 3 .17 20 7 .18 3 .23 3 .17 www. [1- N].domain.com Load Balancer Web Server Farm Switch Application Server Farm Database Server Farm 1 92. 16 8 .1. 1 Load Balancer Back-end Network 1 92. 16 8 .1. 1 Configure