21,99 €
Visually explore the range of built-in and third-party libraries of Perl and Apache
Perl and Apache have been providing Common Gateway Interface (CGI) access to Web sites for 20 years and are constantly evolving to support the ever-changing demands of Internet users. With this book, you will heighten your knowledge and see how to usePerl and Apache to develop dynamic Web sites.
Beginning with a clear, step-by-step explanation of how to install Perl and Apache on both Windows and Linux servers, you then move on to configuring each to securely provide CGI Services. CGI developer and author Adam McDaniel shows techniques for effectively developing and maintaining dynamic sites and he shares real-world examples describing MySQL database access, PayPal credit-card transactions, and sample Facebook and Twitter interfaces.
With this book, you’ll benefit from a wealth of techniques and resources that you won’t find anywhere else.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 782
Veröffentlichungsjahr: 2011
Chapter 1: Introducing Perl and Apache Web Site Development
Introducing Apache and Perl
Introducing the Common Gateway Interface
Understanding CGI from the End-User’s Point of View
Understanding CGI from the Web Browser’s Point of View
Understanding CGI from the Web Server’s Point of View
Understanding CGI from the CGI Program’s Point of View
Compare Perl to Other CGI Languages
Compare Apache to Other Web Servers
Developing Your Web Site
Find Perl- and Apache-Friendly Hosting Providers
Find Help Developing CGI Programs
Chapter 2: Installing Perl on Windows
Introducing ActivePerl for Windows
Introducing Strawberry Perl for Windows
Download ActivePerl for Windows
Install ActivePerl for Windows
Download Strawberry Perl for Windows
Install Strawberry Perl for Windows
Chapter 3: Installing Perl on Linux
Install Perl for Debian/Ubuntu Linux
Install Perl for Red Hat Linux
Download ActivePerl for Linux or Unix
Install ActivePerl for Linux or Unix
Chapter 4: Installing Apache on Windows
Download Apache for Windows
Install Apache for Windows
Configure Apache on Windows
Start and Stop the Apache Service on Windows
Chapter 5: Installing Apache on Linux
Install Apache for Debian/Ubuntu Linux
Install Apache for Red Hat Linux
Configure Apache on Linux
Start and Stop the Apache Service on Linux
Chapter 6: Introducing the Fundamentals of Perl
Understanding Perl Syntax
Understanding the Anatomy of a Perl Script
Create a New Perl Script
Print Output to the Screen
Execute a Perl Script
Introducing Perl Scalars
Store Data into Scalars
Retrieve Data from Scalars
Introducing Perl Arrays
Store Data into Arrays
Retrieve Data from Arrays
Introducing Perl Hashes
Store Data into Hashes
Retrieve Data from Hashes
Chapter 7: Building an Interactive Perl Script
Introducing Perl Conditions
Introducing Perl Operators
Control Program Flow with if, elsif, else
Introducing Perl Loops
Loop Program Flow with foreach, while
Introducing Perl Subroutines
Organize Program Code with Subroutines
Manipulate Variables in Subroutines
Chapter 8: Using Perl References and Modules
Introducing References
Understanding Compound Data Structures
Build an Array or Hash Reference
Deconstruct a Reference
Nest Variable Types with References
Introducing Perl Modules
Create a New Module
Call a Module’s Subroutines as Methods
Chapter 9: Installing Third-Party Perl Modules
Introducing CPAN
Configure CPAN
Search for Perl Modules with CPAN
Install Perl Modules with CPAN
Introducing ActivePerl Perl Package Manager
Configure ActivePerl PPM
Search for Perl Modules with ActivePerl PPM
Install Perl Modules with ActivePerl PPM
Search for Perl Modules in Debian/Ubuntu Linux
Install Perl Modules in Debian/Ubuntu Linux
Search for Perl Modules in Red Hat Linux
Install Perl Modules in Red Hat Linux
Search for and Download Perl Modules Manually
Build and Install Perl Modules Manually
Chapter 10: Configuring Apache to Execute Perl
Introducing the Apache CGI Handler
Create a User Directory for Apache in Windows
Enable the Apache CGI Module and Handler
Configure a Directory to Use the CGI Handler
Understanding the Apache Logs
Configure the Apache Logs
Read the Apache Logs
Forward Perl Activity into the Apache Logs
Forward Perl Activity into the Apache Error Log
Chapter 11: Introducing Do-It-Yourself Perl/CGI Interaction
Create an HTML Form
Read HTTP GET/POST Parameters
Introducing Cookies
Store HTTP Cookies
Retrieve HTTP Cookies
Send an E-Mail Message
Chapter 12: Using Perl’s Built-In CGI Library
Introducing the Built-In CGI Library
Import the CGI Library as an Object
Import the CGI Library’s Routines as Functions
Read HTTP GET/POST Parameters with the CGI Library
Store HTTP Cookies with the CGI Library
Retrieve HTTP Cookies with the CGI Library
Return Useful Error Messages with CGI::Carp
Chapter 13: Separating HTML Code from Perl Code
Understanding the Benefits of Separating HTML from Perl
Introducing the Perl HTML::Template Module
Understanding the Structure of an HTML::Template File
Create a New Template File
Import the HTML::Template Module
Display Data with TMPL_VAR
Control Template Content with TMPL_IF, TMPL_ELSE
Repeat Template Content with TMPL_LOOP
Nest Templates with TMPL_INCLUDE
Create an HTML::Template Header and Footer
Create an HTML::Template Toolbar
Link the Header, Toolbar, and Footer with Dynamic Perl Content
Extend HTML::Template to Non-HTML Formats
Chapter 14: Adding Dynamic Content with Server-Side Includes (SSI)
Introducing Server-Side Includes
Enable the Apache SSI Module and Output Filter
Configure a Directory to Use SSI
Understanding SSI Elements
Import Files with SSI
Execute Programs with SSI
Set Variables within SSI
Retrieve Variables with SSI
Use Conditional Expressions with SSI
Display File Statistics with SSI
Link the Header, Toolbar, and Footer with Static HTML Content
Chapter 15: Authenticating a User Session
Understanding Apache User Authentication
Secure a Directory Path with Apache
Use an Authentication Password File
Require Only Authorized Users
Understanding User Authentication in Perl
Create a Perl Authentication Module
Access a User’s Database
Store User Credentials in a User’s Database
Check for Session Authorization (Step 1)
Display a Login Prompt (Step 2)
Validate a User’s Credentials (Step 3)
Authorize a User’s Session (Step 4)
Restrict Access to a CGI Script
Terminate a User Session
Chapter 16: Interfacing Your Web Site with Facebook
Register Your Web Site as a Facebook Application
Add a Facebook Social Plugin to Your Web Site
Enable Facebook Connect on Your Web Site
Understanding the Facebook Canvas Feature for Applications
Create a Facebook Application with Perl
Chapter 17: Interfacing with the Twitter API Using Perl
Introducing the Twitter APIs
Introducing the Perl Twitter Modules
Register a New Twitter Application
Authenticate to Twitter Using OAuth
Create a MyTwitter Perl Module That Inherits Net::Twitter
Post a Twitter Status Update
Retrieve a Twitter Timeline
Retrieve a List of Twitter Users You Follow
Retrieve a List of Twitter Friends
Retrieve a List of Twitter Followers
Search for Content Using the Twitter Search API
Use the Twitter @Anywhere JavaScript API
Follow Real-Time Activity with the Twitter Streaming API
Chapter 18: Creating Dynamic Images with Perl
Accept a File for Upload
Open an Image with Image::Magick
Resize or Crop an Image with Image::Magick
Resize or Crop an Image
Manipulate an Image with Image::Magick
Save an Image to Disk
Display a Dynamic Image to the Browser
Implement an Image Captcha Test
Produce an Image Gallery
Chapter 19: Facilitating Dynamic AJAX Calls with Perl
Introducing AJAX
Introducing CGI::Ajax
Add CGI::Ajax into Your Perl CGI Scripts
Call Perl Subroutines Through JavaScript
Call JavaScript Through Perl Subroutines
Enable Debug Mode in CGI::Ajax
Integrate Perl and XML
Integrate Perl and JSON
Chapter 20: Processing Credit Card Transactions with Perl
Introducing PayPal
Sign Up for a PayPal Sandbox Account
Create Buyer and Seller Sandbox Accounts
Retrieve Your Seller’s Sandbox API Credentials
Use Business::PayPal::NVP to Connect to PayPal
Process a Credit Card Payment with PayPal
Use the PayPal Express Checkout API
Search Your PayPal Transaction History
View a PayPal Transaction’s Details
Refund a PayPal Transaction
Chapter 21: Accessing a Back-End MySQL Database with Perl
Introducing the MySQL Database
Understanding the SQL Syntax
Download MySQL for Windows
Install MySQL for Windows
Install MySQL for Debian/Ubuntu Linux
Install MySQL for Red Hat Linux
Introducing the Perl DBI Library
Connect to a MySQL Database with the DBI Library
Retrieve SQL Data Using the DBI Library
Display SQL Data Through HTML::Template
Change SQL Data Using the DBI Library
Chapter 22: Securing Dynamic Web Sites
Understanding TLS/SSL Encryption
Create a Private SSL Key
Generate an SSL Certificate Signing Request
Sign Your Own CSR to Create a Test SSL Certificate
Submit Your CSR to Be Signed by a Certificate Authority
Configure Apache to Use TLS/SSL
Understanding Security in Perl CGI Development
Limit CGI Access in Apache
Identify Unusual Activity on Your Web Site
Sanitize User Content in Perl CGI
Validate User Content in Perl CGI
Chapter 23: Speeding Up Dynamic Web Sites
Introducing the Apache mod_perl Module
Install the Apache mod_perl Module for Windows
Install the Apache mod_perl Module for Linux
Configure the Apache mod_perl Module
Understanding mod_perl’s Caveats
Appendix A: Perl Reference
Appendix B: Apache Configure and Module Reference
Appendix C: Useful Perl Modules
Perl and Apache
Your visual blueprint™ for developing dynamic Web content
by Adam McDaniel
Perl and Apache: Your visual blueprint™ for developing dynamic Web content
Published by Wiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256
www.wiley.com
Published simultaneously in Canada
Copyright © 2011 by Wiley Publishing, Inc., Indianapolis, Indiana
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, 201-748-6011, fax 201-748-6008, or online at www.wiley.com/go/permissions.
Library of Congress Control Number: 2010934753
ISBN: 978-1-118-03637-2
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Trademark Acknowledgments
Wiley, the Wiley Publishing logo, Visual, the Visual logo, Visual Blueprint, Read Less - Learn More and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this book.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
FOR PURPOSES OF ILLUSTRATING THE CONCEPTS AND TECHNIQUES DESCRIBED IN THIS BOOK, THE AUTHOR HAS CREATED VARIOUS NAMES, COMPANY NAMES, MAILING, E-MAIL AND INTERNET ADDRESSES, PHONE AND FAX NUMBERS AND SIMILAR INFORMATION, ALL OF WHICH ARE FICTITIOUS. ANY RESEMBLANCE OF THESE FICTITIOUS NAMES, ADDRESSES, PHONE AND FAX NUMBERS AND SIMILAR INFORMATION TO ANY ACTUAL PERSON, COMPANY AND/OR ORGANIZATION IS UNINTENTIONAL AND PURELY COINCIDENTAL.
Contact Us
For general information on our other products and services please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993 or fax 317-572-4002.
For technical support please visit www.wiley.com/techsupport.
The Diwan-I-Khas of the palace complex at Fatehpur Sikri
The history of this intriguing pavilion is almost as enigmatic as the structure itself. Dating to the 17th century, this private audience hall is remarkable for its richly carved central pillar, unique in Mughal architecture. One school of thought holds that the design of the building and its stone centerpiece may reflect some Hindu mandala in which the central column represents the axis of the world. As such, it conferred superior status upon the emperor who received visiting dignitaries while seated at its base.
Explore India’s countless architectural treasures in Frommer’s India, 4th Edition (ISBN 978-0-470-55610-8) available wherever books are sold or at www.Frommers.com.
Sales
Contact Wileyat (877) 762-2974or (317) 572-4002.
Credits
Acquisitions Editor
Aaron Black
Project Editor
Jade Williams
Technical Editor
Allen Wyatt
Copy Editor
Marylouise Wiack
Editorial Director
Robyn Siesky
Editorial Manager
Rosemarie Graham
Business Manager
Amy Knies
Senior Marketing Manager
Sandy Smith
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Barry Pruett
Project Coordinator
Patrick Redmond
Graphics and Production Specialists
Andrea HornbergerJennifer Mayberry
Quality Control Technician
Jessica Kramer
Proofreading
Tricia Liebig
Indexing
Potomac Indexing, LLC
Media Development Project Manager
Laura Moss
Media Development Assistant Project Manager
Jenny Swisher
Screen Artist
Ana CarrilloJill ProllRon Terry
Illustrator
Cheryl Grubbs
About the Author
Adam McDaniel has been desgining, developing, modifying, and maintaining computer programs of one language or another since 1993, and has been an active proponent of Perl since being introduced to the langauge in 1998. In early 1999, Adam led a team of developers implementing an E-Commerce fulfillment engine written entirely in Perl for a virtual shopping mall. Afterwards, he worked for Hitachi ID Systems for over 8 years, during which he designed and implemented security recommondations and software for various Fortune 500 companies across the United States and Europe.
Always interested in new technologies and architectures, development credits include an open-source offline HTML reader for the Palm OS platform, contributions to the Linux Kernel, plus countless utility and speciality programs. In 2006, Adam produced the Array.org Netbook Kernel software download and Web site, allowing users to download an optimized build of the Linux kernel, specific for the Ubuntu Linux distribution. This site, implemented using Perl and Apache, became hugely popular resulting in millions unique visitors in just a few months. It actually prompted him to move away from security architecture and design and into a new field: Linux distribution architecture. Today, Adam works as the Lead OS Architect for Jolicloud, a Paris-based Linux distribution that specializes in a cloud-based user interface designed for netbooks, tablets, and other portable computers.
Author’s Acknowledgments
This book is actually the product of many significant people, projects, and events, without all of which, this project would never have been possible.
First and foremost, I must thank my wife, Shauna, for her un-ending patience, understanding, encouragement, and love, both silent and vocal, which she happily supplied while I toiled away endlessly on this project. I must also thank my editors at Wiley Publishing, espcially Aaron Black and Jade Williams, for their expert guideance, advice, and patience, despite their occasional prodding over e-mail.
This book could not be possible without hundreds of thousands of developers who have dedicated their time and expertise to open-source software. Projects like the Linux Kernel, Perl, Apache, and everything in-between serves as an excellent model of design, efficiency, and dedication to people like me and other technology enthusiasts.
Finally, regarding significant events, I have to thank our unpredictable Canadian winter weather. In January 2008, we experienced seven days of -40 degree weather; this caused a water pipe to burst and flood my basement with 18 inches of water while I was away from home. Had my basement not flooded, I would never have replaced an old waterlogged laptop with a brand new EeePC netbook through the insurance claim. Without that, I would have never become interested in netbook hardware, nor in customizing the Linux kernel for that hardware. And I certainly would have never created my Array.org Netbook Kernel Web site, through which Aaron Black would never have contacted me, and this book would never have come into existence.
Dedication
This book is dedicated to my father, William McDaniel, who knew about this project, but never got the chance to see the final result.
How to Use This Book
Who This Book Is For
This book is for advanced computer users who want to take their knowledge of this particular technology or software application to the next level.
The Conventions in This Book
Steps
This book uses a step-by-step format to guide you easily through each task. Numbered steps are actions you must do; bulleted steps clarify a point, step, or optional feature; and indented steps give you the result.
Notes
Notes give additional information — special conditions that may occur during an operation, a situation that you want to avoid, or a cross reference to a related area of the book.
Icons and Buttons
Icons and buttons show you exactly what you need to click to perform a step.
Extra or Apply It
An Extra section provides additional information about the preceding task — insider information and tips for ease and efficiency. An Apply It section takes the code from the preceding task one step further and allows you to take full advantage of it.
Bold
Bold type shows text or numbers you must type.
Italics
Italic type introduces and defines a new term.
Courier Font
Courier font indicates the use of scripting language code such as statements, operators, or functions, and code such as objects, methods, or properties.
Chapter 1: Introducing Perl and Apache Web Site Development
Introducing Apache and Perl
Since the inception of the World Wide Web in 1989, users, academics, and professionals have been inspired by this new canvas to present information over the Internet. The jump from a text-based interface to a graphical interface would capture the world’s imagination on presenting information to the masses.
Content-owners can now store information in a series of files on a server, with end-users accessing that data at their convenience. In the earlier days of the Internet, the server-side information was stored as simple static text files and images, meaning that files were only changed when someone manually made a change and uploaded the new file to the server. As a result, most Web sites did not change very often. With the introduction of the Common Gateway Interface (CGI), Web sites could now use programs in place of static files to dynamically create on-demand content that was unique for every user.
Anyone wanting to participate on the graphical Internet requires a client-side program, called a Web browser. This program is installed onto a local workstation, and requires an outgoing connection to the public Internet. The browser establishes a communication link through the network to a server-side counterpart, called a Web server, submits a request, and waits for a response. It is the server’s job to interpret the request being made, assess the requester’s credentials, open the file or execute a program using CGI, and transmit the results back to the user. Once the browser receives the data, it must decode the transfer and render a graphical representation of the text and images so that the user can interpret the information.
Many Web browser programs are freely available for download, depending on the user’s choice of operating system. Popular options include Mozilla Firefox, Google Chrome, Microsoft Internet Explorer, and Apple Safari. For the content-owner, a Web site is delivered to the user’s browser by various Web server programs, like Apache HTTP Server or Microsoft Internet Information Service (IIS). Again, the options available depend on the choice of operating system on the server.
The program that utilizes CGI typically runs on the same computer as the Web server. There are multiple languages available today that can interact with CGI, including PHP, Java, and even C and C++, but this book focuses on the Practical Extraction and Report Language, more commonly known as Perl.
The Apache HTTP Server
The Apache HTTP Server, widely viewed today as the de facto Web server for Unix and Windows platforms, handles more than 90percent of World Wide Web traffic.
A History of Apache
First released in 1995, Apache evolved from the remains of the now defunct NCSA HTTPd program, which was the first Web server created to support the Hypertext Transfer Protocol, or HTTP.
Early Web servers were only capable of relaying static content directly from files stored on the Web server’s hard drive. Eventually, the CGI protocol was standardized and support was added to Apache.
Versions of Apache
Because Apache has been in development for many years, new versions are constantly being released as major version milestones. The latest major release, Apache 2.2, supports a wide range of configuration features, performance enhancements, and third-party modules.
Earlier releases, such as Apache 2.0 and 1.3, are still available and supported. However, you should only consider using an older version if you have a specific reason to do so. If you are just starting out with Apache, use the latest stable release available, Apache 2.2.
The End-User Experience
To provide a pleasurable and esthetically pleasing Web site, the Web site author composes HTML content that describes the site’s text, images, and layout. Early Web browsers lacked many of today’s client-side technologies that are used to create dynamic content, such as Flash, Java, and JavaScript. Instead, they relied on the Web server to provide the entire end-user experience.
Because today’s Internet has many options for dynamic content, a Web site author may choose any type of technology that is available: client-side, server-side, or even both. Intelligently mixing technologies that complement each other can create a memorable site that your users will want to visit again.
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
