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 [...]... 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... 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 821 -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... 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 821 -2 PO1.F 2/ 22/ 02 10:09 AM Page 2 c4 821 -2 ch01.F 2/ 22/ 02. .. 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 431935 3.45 383078 2. 83 Zeus 1740 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... 321 323 323 326 327 328 328 329 330 335 335 336 338 341 3 42 3 42 370 370 371 371 371 371 373 374 a4 821 -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... 709 Appendix C: Online Apache Resources 713 Appendix D: What’s on the CD-ROM? 719 Index 723 End-User License Agreement 755 xxix a4 821 -2 FM.F 2/ 22/ 02 10:09 AM Page xxx b4 821 -2 PO1.F 2/ 22/ 02 10:09 AM Page 1 P I R T I Getting Started n this part, I show you why Apache is a great Web server; where to get it... Web Site This book has a Web site at http://www.evoknow.com/kabir /apache2 You can visit this Web site for updated contents, errata, and FAQ xi a4 821 -2 FM.F 2/ 22/ 02 10:09 AM Page xii a4 821 -2 FM.F 2/ 22/ 02 10:09 AM Page xiii Acknowledgments I would like to thank the Apache Group for creating the most powerful, extensible, and modular Web server in the world I give special thanks to Ralf S Engelschall Ralf,... Managing Apache from the command-line Running multiple Apache services 569 570 570 574 574 577 577 578 xxvii a4 821 -2 FM.F xxviii 2/ 22/ 02 10:09 AM Page xxviii Apache Server 2 Bible Chapter 21 : Configuring Apache for Windows 579 Windows httpd.conf Syntax Tuning Apache for Performance Testing Apache. .. platform with version 2. 0, Apache was already in Windows market with Version 1.3.x We will see a lot of Windows systems switching to Apache from Microsoft Internet Information Server (IIS) because Apache 2. 0 architecture gives it the power it needed to compete natively c4 821 -2 ch01.F 2/ 22/ 02 10:10 AM Page 5 Chapter 1 ✦ Apache: The Number One Web Server Apache: The Beginning Here is a bit of Apache history . Web servers for reliability and security 4 821 -2 cover 2/ 6/ 02 9 :20 AM Page 1 Apache Server 2 Bible a4 821 -2 FM.F 2/ 22/ 02 10:09 AM Page i a4 821 -2 FM.F 2/ 22/ 02 10:09 AM Page ii Apache Server 2 Bible Mohammed. kabir@evoknow.com. a4 821 -2 FM.F 2/ 22/ 02 10:09 AM Page vi To the memory of my mother, Nazma Bathen. a4 821 -2 FM.F 2/ 22/ 02 10:09 AM Page vii a4 821 -2 FM.F 2/ 22/ 02 10:09 AM Page viii Preface W elcome to Apache Server 2. 0 http://www.evoknow.com/kabir /apache2 . You can visit this Web site for updated contents, errata, and FAQ. Cross- Reference On the CD-ROM Caution Tip Note a4 821 -2 FM.F 2/ 22/ 02 10:09 AM Page xi a4 821 -2 FM.F 2/ 22/ 02 10:09