Book description
mod_perl embeds the popular programming language Perl in the Apache web server, giving rise to a fast and powerful web programming environment. Practical mod_perl is the definitive book on how to use, optimize, and troubleshoot mod_perl.
New mod_perl users will learn how to quickly and easily get mod_perl compiled and installed. But the primary purpose of this book is to show you how to take full advantage of mod_perl: how to make a mod_perl-enabled Web site as fast, flexible, and easily-maintainable as possible. The authors draw from their own personal experience in the field, as well as the combined experience of the mod_perl community, to present a rich and complete picture of how to set up and maintain a successful mod_perl site.
This book is also the first book to cover the "next generation" of mod_perl: mod_perl 2.0, a completely rewritten version of mod_perl designed for integration with Apache 2.0, which for the first time supports threads.
The book covers the following topics, and more:
- Configuring mod_perl optimally for your web site
- Porting and optimizing programs for a mod_perl environment
- Performance tuning: getting the very fastest performance from your site
- Controlling and monitoring the server to circumvent crashes and clogs
- Integrating with databases efficiently and painlessly
- Debugging tips and tricks
- Maximizing security
Publisher resources
Table of contents
- Practical mod_perl
- Preface
-
I. mod_perl Administration
- 1. Introducing CGI and mod_perl
-
2. Getting Started Fast
- 2.1. Installing mod_perl 1.0 in Three Steps
- 2.2. Installing mod_perl on Unix Platforms
- 2.3. Configuring and Starting the mod_perl Server
- 2.4. Installing mod_perl for Windows
- 2.5. Preparing the Scripts Directory
- 2.6. A Sample Apache::Registry Script
- 2.7. A Simple mod_perl Content Handler
- 2.8. Is This All We Need to Know About mod_perl?
- 2.9. References
-
3. Installing mod_perl
-
3.1. Configuring the Source
- 3.1.1. Controlling the Build Process
- 3.1.2. Activating Callback Hooks
- 3.1.3. Activating Standard API Features
- 3.1.4. Enabling Extra Features
- 3.1.5. Reusing Configuration Parameters
- 3.1.6. Discovering Whether a Feature Was Enabled
- 3.1.7. Using an Alternative Configuration File
- 3.1.8. perl Makefile.PL Troubleshooting
- 3.2. Building mod_perl (make)
- 3.3. Testing the Server (make test)
- 3.4. Installation (make install)
- 3.5. Installation Scenarios for Standalone mod_perl
- 3.6. Building mod_perl with Other Components
- 3.7. Installing mod_perl with the CPAN.pm Interactive Shell
- 3.8. Installing mod_perl on Multiple Machines
-
3.9. Installation into a Nonstandard Directory
- 3.9.1. Installing Perl Modules into a Nonstandard Directory
- 3.9.2. Finding Modules Installed in Nonstandard Directories
- 3.9.3. Using the CPAN.pm Shell with Nonstandard Installation Directories
- 3.9.4. Making a Local Apache Installation
- 3.9.5. Nonstandard mod_perl-Enabled Apache Installation
- 3.9.6. Nonstandard mod_perl-Enabled Apache Installation with CPAN.pm
- 3.10. How Can I Tell if mod_perl Is Running?
- 3.11. General Notes
- 3.12. References
-
3.1. Configuring the Source
-
4. mod_perl Configuration
-
4.1. Apache Configuration
- 4.1.1. Configuration Files
- 4.1.2. Configuration Directives
- 4.1.3. <Directory>, <Location>, and <Files> Sections
- 4.1.4. Merging <Directory>, <Location>, and <Files> Sections
- 4.1.5. Subgrouping of <Directory>, <Location>, and <Files> Sections
- 4.1.6. Options Directive Merging
- 4.1.7. MinSpareServers, MaxSpareServers, StartServers, MaxClients, and MaxRequestsPerChild
-
4.2. mod_perl Configuration
- 4.2.1. Alias Configurations
- 4.2.2. <Location /perl> Sections
- 4.2.3. PerlModule and PerlRequire
- 4.2.4. Perl*Handlers
- 4.2.5. The handler( ) Subroutine
- 4.2.6. Investigating the Request Phases
- 4.2.7. Stacked Handlers
- 4.2.8. Perl Method Handlers
- 4.2.9. PerlFreshRestart
- 4.2.10. PerlSetEnv and PerlPassEnv
- 4.2.11. PerlSetVar and PerlAddVar
- 4.2.12. PerlSetupEnv
- 4.2.13. PerlWarn and PerlTaintCheck
- 4.3. The Startup File
- 4.4. Apache Configuration in Perl
- 4.5. Validating the Configuration Syntax
- 4.6. The Scope of mod_perl Configuration Directives
- 4.7. Apache Restarts Twice
- 4.8. Enabling Remote Server Configuration Reports
- 4.9. Tips and Tricks
- 4.10. Configuration Security Concerns
- 4.11. General Pitfalls
- 4.12. References
-
4.1. Apache Configuration
-
5. Web Server Control, Monitoring, Upgrade, and Maintenance
- 5.1. Starting the Server in Multi-Process Mode
- 5.2. Starting the Server in Single-Process Mode
- 5.3. Using kill to Control Processes
- 5.4. Using apachectl to Control the Server
- 5.5. Validating Server Configuration
- 5.6. Setuid root Startup Scripts
- 5.7. Preparing for Machine Reboot
-
5.8. Upgrading a Live Server
- 5.8.1. Upgrading Intranet Servers
-
5.8.2. Upgrading 24 × 7 Internet Servers
- 5.8.2.1. The server cluster
-
5.8.2.2. The single server
- 5.8.2.2.1. Upgrading live server components by swapping machines
- 5.8.2.2.2. Upgrading a live server with port forwarding
- 5.8.2.2.3. Upgrading a live server with prepackaged components
- 5.8.2.2.4. Upgrading a live server using symbolic links
- 5.8.2.2.5. Upgrading Perl code
- 5.8.2.2.6. Moving files and restarting the server
- 5.8.2.2.7. Using CVS for code upgrades
- 5.8.3. Disabling Scripts and Handlers on a Live Server
- 5.8.4. Scheduled Routine Maintenance
- 5.9. Three-Tier Server Scheme: Development, Staging, and Production
- 5.10. Web Server Monitoring
- 5.11. Server Maintenance Chores
- 5.12. References
-
6. Coding with mod_perl in Mind
- 6.1. Before You Start to Code
- 6.2. Exposing Apache::Registry Secrets
- 6.3. Namespace Issues
- 6.4. Perl Specifics in the mod_perl Environment
- 6.5. CHECK and INIT Blocks
- 6.6. Apache::Registry Specifics
- 6.7. Transition from mod_cgi Scripts to Apache Handlers
- 6.8. Loading and Reloading Modules
- 6.9. Handling the “User Pressed Stop Button” Case
- 6.10. Handling Server Timeout Cases and Working with $SIG{ALRM}
- 6.11. Generating Correct HTTP Headers
- 6.12. Method Handlers: The Browse and See, Browse and View Example
- 6.13. References
-
II. mod_perl Performance
- 7. Identifying Your Performance Problems
-
8. Choosing a Platform for the Best Performance
- 8.1. Choosing the Right Operating System
-
8.2. Choosing the Right Hardware
- 8.2.1. Machine Strength Demands According to Expected Site Traffic
- 8.2.2. A Single Strong Machine Versus Many Weaker Machines
- 8.2.3. Getting a Fast Internet Connection
- 8.2.4. Tuning I/O Performance
- 8.2.5. How Much Memory Is Enough?
- 8.2.6. Getting a Fault-Tolerant CPU
- 8.2.7. Detecting and Avoiding Bottlenecks
- 8.2.8. Solving Hardware Requirement Conflicts
- 8.3. References
- 9. Essential Tools for Performance Tuning
-
10. Improving Performance with Shared Memory and Proper Forking
- 10.1. Sharing Memory
-
10.2. Forking and Executing Subprocessesfrom mod_perl
- 10.2.1. Forking a New Process
- 10.2.2. Freeing the Parent Process
- 10.2.3. Detaching the Forked Process
- 10.2.4. Avoiding Zombie Processes
- 10.2.5. A Complete Fork Example
- 10.2.6. Starting a Long-Running External Program
- 10.2.7. Starting a Short-Running External Program
- 10.2.8. Executing system( ) or exec( ) in the Right Way
- 10.3. References
-
11. Tuning Performance by Tweaking Apache’s Configuration
- 11.1. Setting the MaxClients Directive
- 11.2. Setting the MaxRequestsPerChild Directive
- 11.3. Setting MinSpareServers, MaxSpareServers, and StartServers
- 11.4. KeepAlive
- 11.5. PerlSetupEnv
- 11.6. Reducing the Number of stat( ) Calls Made by Apache
- 11.7. Symbolic Links Lookup
- 11.8. Disabling DNS Resolution
- 11.9. Response Compressing
- 11.10. References
-
12. Server Setup Strategies
- 12.1. mod_perl Deployment Overview
- 12.2. Standalone mod_perl-Enabled Apache Server
- 12.3. One Plain and One mod_perl-Enabled Apache Server
- 12.4. One Light Non-Apache and One mod_perl-Enabled Apache Server
- 12.5. Adding a Proxy Server in httpd Accelerator Mode
- 12.6. The Squid Server and mod_perl
- 12.7. Apache’s mod_proxy Module
- 12.8. mod_rewrite Examples
- 12.9. Getting the Remote Server IP in the Backend Server in the Proxy Setup
- 12.10. Frontend/Backend Proxying with Virtual Hosts
- 12.11. HTTP Authentication with Two Servers and a Proxy
- 12.12. When One Machine Is Not Enough for Your RDBMS DataBase and mod_perl
- 12.13. Running More than One mod_perl Server on the Same Machine
- 12.14. SSL Functionality and a mod_perl Server
- 12.15. Uploading and Downloading Big Files
- 12.16. References
-
13. TMTOWTDI: Convenience and Habit Versus Performance
- 13.1. Apache::Registry PerlHandler Versus Custom PerlHandler
- 13.2. Apache::args Versus Apache::Request::param Versus CGI::param
- 13.3. Buffered Printing and Better print( ) Techniques
- 13.4. Interpolation, Concatenation, or List
- 13.5. Keeping a Small Memory Footprint
- 13.6. Object Methods Calls Versus Function Calls
- 13.7. Using the Perl stat( ) Call’s Cached Results
- 13.8. time( ) System Call Versus $r->request_time
- 13.9. Printing Unmodified Files
- 13.10. Caching and Pre-Caching
- 13.11. Caching with Memoize
- 13.12. Comparing Runtime Performance of Perl and C
- 13.13. References
- 14. Defensive Measures for Performance Enhancement
- 15. Improving Performance Through Build Options
- 16. HTTP Headers for Optimal Performance
-
III. Databases and mod_perl
- 17. Databases Overview
- 18. mod_perl Data-Sharing Techniques
- 19. DBM and mod_perl
-
20. Relational Databases and mod_perl
- 20.1. Persistent Database Connections with Apache::DBI
- 20.2. Improving Performance
- 20.3. DBI Debug Techniques
- 20.4. References
-
IV. Debugging and Troubleshooting
-
21. Error Handling and Debugging
- 21.1. Warnings and Errors Explained
- 21.2. Debugging Code in Single-Server Mode
- 21.3. Tracing System Calls
- 21.4. Tracing mod_perl-Specific Perl Calls
-
21.5. Debugging Perl Code
- 21.5.1. Locating and Correcting Syntax Errors
- 21.5.2. Using Apache::FakeRequest to Debug Apache Perl Modules
- 21.5.3. Using print( ) for Debugging
- 21.5.4. Using print( ) and Data::Dumper for Debugging
- 21.5.5. The Importance of a Good, Concise Coding Style
- 21.5.6. Introduction to the Perl Debugger
- 21.5.7. Interactive Perl Debugging Under mod_cgi
- 21.5.8. Noninteractive Perl Debugging Under mod_perl
- 21.5.9. Interactive mod_perl Debugging
- 21.6. Analyzing Dumped core Files
- 21.7. Hanging Processes: Detection and Diagnostics
- 21.8. Useful Debug Modules
- 21.9. Looking Inside the Server
- 21.10. References
-
22. Troubleshooting mod_perl
- 22.1. Configuration and Startup
-
22.2. Code Parsing and Compilation
- 22.2.1. Value of $x will not stay shared at - line 5
- 22.2.2. Value of $x may be unavailable at - line 5
- 22.2.3. Can’t locate loadable object for module ...
- 22.2.4. Can’t locate object method “get_handlers” ...
- 22.2.5. Missing right bracket at line ...
- 22.2.6. Can’t load `.../auto/DBI/DBI.so’ for module DBI
-
22.3. Runtime
- 22.3.1. foo ... at /dev/null line 0
- 22.3.2. Segfaults When Using XML::Parser
- 22.3.3. exit signal Segmentation fault (11)
- 22.3.4. CGI Code Is Returned as Plain Text Instead of Being Executed
- 22.3.5. rwrite returned -1
- 22.3.6. Global symbol “$foo” requires explicit package name
- 22.3.7. Use of uninitialized value at (eval 80) line 12
- 22.3.8. Undefined subroutine &Apache::ROOT::perl::test_2epl::some_function called at
- 22.3.9. Callback called exit
- 22.3.10. Out of memory!
- 22.3.11. syntax error at /dev/null line 1, near “line arguments:”
- 22.4. Shutdown and Restart
- 23. Getting Help and Online Resources
-
21. Error Handling and Debugging
-
V. mod_perl 2.0
-
24. mod_perl 2.0: Installation and Configuration
- 24.1. What’s New in Apache 2.0
- 24.2. What’s New in Perl 5.6.0-5.8.0
- 24.3. What’s New in mod_perl 2.0
- 24.4. Installing mod_perl 2.0
- 24.5. Configuring mod_perl 2.0
- 24.6. Resources
-
25. Programming for mod_perl 2.0
- 25.1. Migrating to and Programming with mod_perl 2.0
- 25.2. New Apache Phases and Corresponding Perl*Handlers
- 25.3. I/O Filtering
-
24. mod_perl 2.0: Installation and Configuration
-
VI. Appendixes
-
A. mod_perl Recipes
- A.1. Emulating the Authentication Mechanism
- A.2. Reusing Data from POST Requests
- A.3. Redirecting POST Requests
- A.4. Redirecting While Maintaining Environment Variables
- A.5. Handling Cookies
- A.6. Sending Multiple Cookies with the mod_perl API
- A.7. Sending Cookies in REDIRECT Responses
- A.8. CGI::params in the mod_perlish Way
- A.9. Sending Email from mod_perl
- A.10. mod_rewrite in Perl
- A.11. Setting PerlHandler Based on MIME Type
- A.12. Singleton Database Handles
- A.13. Terminating a Child Process on Request Completion
- A.14. References
-
B. Apache Perl Modules
-
B.1. Development-Stage Modules
- B.1.1. Apache::Reload—Automatically Reload Changed Modules
- B.1.2. Apache::PerlVINC—Allow Module Versioning in <Location> and <VirtualHost> blocks
- B.1.3. Apache::DProf—Hook Devel::DProf into mod_perl
- B.1.4. Apache::SmallProf—Hook Devel::SmallProf into mod_perl
- B.1.5. Apache::FakeRequest—Fake Request Object for Debugging
- B.1.6. Apache::test—Facilitate Testing of Apache::* Modules
-
B.2. Modules to Aid Debugging
- B.2.1. Apache::DB—Hooks for the Interactive Perl Debugger
- B.2.2. Apache::Debug—Utilities for Debugging Embedded Perl Code
- B.2.3. Apache::DebugInfo—Send Debug Information to Client
- B.2.4. Apache::Leak—Module for Tracking Memory Leaks in mod_perl Code
- B.2.5. Apache::Peek—A Data Debugging Tool for the XS Programmer
- B.2.6. Apache::Symbol—Avoid the Mandatory `Subroutine Redefined’ Warning
- B.2.7. Apache::Symdump—Symbol Table Snapshots
-
B.3. Control and Monitoring Modules
- B.3.1. Apache::Watchdog::RunAway—Hanging Processes Monitor and Terminator
- B.3.2. Apache::VMonitor—Visual System and Apache Server Monitor
- B.3.3. Apache::SizeLimit—Limit Apache httpd Processes
- B.3.4. Apache::GTopLimit—Limit Apache httpd Processes
- B.3.5. Apache::TimedRedirect—Redirect URLs for a Given Time Period
- B.3.6. Apache::Resource—Limit Resources Used by httpd Children
- B.3.7. Apache::Status—Embedded Interpreter Status Information
-
B.4. Server Configuration Modules
- B.4.1. Apache::ModuleConfig—Interface to Configuration API
- B.4.2. Apache::PerlSections—Utilities for Working with <Perl> Sections
- B.4.3. Apache::httpd_conf—Generate an httpd.conf File
- B.4.4. Apache::src—Methods for Locating and Parsing Bits of Apache Source Code
- B.4.5. Apache::ConfigFile—Parse an Apache-Style httpd.conf Configuration File
- B.5. Authentication-Phase Modules
- B.6. Authorization-Phase Modules
- B.7. Access-Phase Modules
- B.8. Type Handlers
- B.9. Trans Handlers
- B.10. Fixup Handlers
-
B.11. Generic Content-Generation Modules
- B.11.1. Apache::Registry and Apache::PerlRun
- B.11.2. Apache::RegistryNG—Apache::Registry New Generation
- B.11.3. Apache::RegistryBB—Apache::Registry Bare Bones
- B.11.4. Apache::Request (libapreq)—Generic Apache Request Library
- B.11.5. Apache::Dispatch—Call PerlHandlers with the Ease of Registry Scripts
-
B.12. Application-Specific Content-Generation Modules
- B.12.1. Apache::AutoIndex—Perl Replacement for the mod_autoindex and mod_dir Apache Modules
- B.12.2. Apache::WAP::AutoIndex—WAP Demonstration Module
- B.12.3. Apache::WAP::MailPeek—Demonstrate Use of WML Delivery
- B.12.4. Apache::Archive—Expose Archive Files Through the Apache Web Server
- B.12.5. Apache::Gateway—Implement a Gateway
- B.12.6. Apache::NNTPGateway—NNTP Interface for a mod_perl-Enabled Apache Web Server.
- B.12.7. Apache::PrettyPerl—Syntax Highlighting for Perl Files
- B.12.8. Apache::PrettyText—Reformat .txt Files for Client Display
- B.12.9. Apache::RandomLocation—Random File Display
- B.12.10. Apache::Stage—Manage a Staging Directory
- B.12.11. Apache::Roaming—A mod_perl Handler for Roaming Profiles
- B.12.12. Apache::Backhand—Write mod_backhand Functions in Perl
- B.13. Database Modules
-
B.14. Toolkits and Frameworks for Content-Generation and Other Phases
- B.14.1. Apache::ASP—Active Server Pages for Apache with mod_perl
- B.14.2. Apache::AxKit—XML Toolkit for mod_perl
- B.14.3. HTML::Embperl—Embed Perl into HTML
- B.14.4. Apache::EmbperlChain—Process Embedded Perl in HTML in the OutputChain
- B.14.5. Apache::ePerl—Embedded Perl 5 Language
- B.14.6. Apache::iNcom—E-Commerce Framework
- B.14.7. Apache::Mason—Perl-Based Web Site Development and Delivery System
- B.14.8. Apache::PageKit—Web Applications Framework
- B.14.9. Template Toolkit—Template Processing System
-
B.15. Output Filters and Layering Modules
- B.15.1. Apache::OutputChain—Chain Stacked Perl Handlers
- B.15.2. Apache::Clean—mod_perl Interface Into HTML::Clean
- B.15.3. Apache::Filter—Alter the Output of Previous Handlers
- B.15.4. Apache::GzipChain—Compress HTML (or Anything) in the OutputChain
- B.15.5. Apache::PassFile—Send File via OutputChain
- B.15.6. Apache::Gzip—Auto-Compress Web Files with gzip
- B.15.7. Apache::Compress—Auto-Compress Web Files with gzip
- B.15.8. Apache::Layer—Layer Content Tree Over One or More Others
- B.15.9. Apache::Sandwich—Layered Document (Sandwich) Maker
- B.15.10. Apache::SimpleReplace—Simple Template Framework
- B.15.11. Apache::SSI—Implement Server-Side Includes in Perl
-
B.16. Logging-Phase Handlers
- B.16.1. Apache::RedirectLogFix—Correct Status While Logging
- B.16.2. Apache::DBILogConfig—Logs Access Information in a DBI Database
- B.16.3. Apache::DBILogger—Tracks What’s Being Transferred in a DBI Database
- B.16.4. Apache::DumpHeaders—Watch HTTP Transaction via Headers
- B.16.5. Apache::Traffic—Track Hits and Bytes Transferred on a Per-User Basis
-
B.17. Core Apache Modules
- B.17.1. Apache::Module—Interface to Apache C Module Structures
- B.17.2. Apache::ShowRequest—Show Phases and Module Participation
- B.17.3. Apache::SubProcess—Interface to Apache Subprocess API
- B.17.4. Apache::Connection—Interface to the Apache conn_rec Data Structure
- B.17.5. Apache::Constants—Constants Defined in httpd.h
- B.17.6. Apache::ExtUtils—Utilities for Apache C/Perl Glue
- B.17.7. Apache::File—Advanced Functions for Manipulating Files on the Server Side
- B.17.8. Apache::Log—Interface to Apache Logging
- B.17.9. Apache::LogFile—Interface to Apache’s Logging Routines
- B.17.10. Apache::Scoreboard—Perl Interface to Apache’s scoreboard.h
- B.17.11. Apache::Server—Perl Interface to the Apache server_rec Struct
- B.17.12. Apache::Table—Perl Interface to the Apache Table Struct
- B.17.13. Apache::URI—URI Component Parsing and Unparsing
- B.17.14. Apache::Util—Perl Interface to Apache C Utility Functions
-
B.18. Other Miscellaneous Modules
- B.18.1. Apache::Session—Maintain Session State Across HTTP Requests
- B.18.2. Apache::RequestNotes—Easy, Consistent Access to Cookie and Form Data Across Each Request Phase
- B.18.3. Apache::Cookie—HTTP Cookies Class
- B.18.4. Apache::Icon—Look Up Icon Images
- B.18.5. Apache::Include—Utilities for mod_perl/mod_include Integration
- B.18.6. Apache::Language—Perl Transparent Language Support for Apache Modules and mod_perl Scripts
- B.18.7. Apache::Mmap—Perl Interface to the mmap(2) System Call
- B.18.8. Apache::GD::Graph—Generate Graphs in an Apache Handler
- B.18.9. Apache::Motd—Provide motd (Message of the Day) Functionality to a Web Server
- B.18.10. Apache::ParseLog—Object-Oriented Perl Extension for Parsing Apache Log Files
- B.18.11. Apache::RegistryLoader—Compile Apache::Registry Scripts at Server Startup
- B.18.12. Apache::SIG—Override Apache Signal Handlers with Perl’s Signal Handlers
- B.18.13. Apache::TempFile—Allocate Temporary Filenames for the Duration of a Request
- B.18.14. Xmms—Perl Interface to the xmms Media Player
- B.18.15. Module::Use—Log and Load Used Perl Modules
-
B.1. Development-Stage Modules
- C. ISPs Providing mod_perl Services
- D. The Template Toolkit
- E. The AxKit XML Application Server
- F. HTTP Status Codes
-
A. mod_perl Recipes
- Index
- About the Authors
- Colophon
- Copyright
Product information
- Title: Practical mod_perl
- Author(s):
- Release date: May 2003
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9780596002275
You might also like
book
Linux in a Nutshell, 6th Edition
Everything you need to know about Linux is in this book. Written by Stephen Figgins, Ellen …
book
Apache Cookbook, 2nd Edition
There's plenty of documentation on installing and configuring the Apache web server, but where do you …
book
Apache Cookbook
Apache is far and away the most widely used web server platform in the world. Both …
book
A Practical Guide to Ubuntu Linux, Third Edition
The Most Complete, Easy-to-Follow Guide to Ubuntu Linux The #1 Ubuntu server resource, fully updated for …