• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Apache2 BootCamp : Serving Dynamic Content with CGI

Apache2 BootCamp : Serving Dynamic Content with CGI






Total Views
Views on SlideShare
Embed Views



1 Embed 4

http://jujo00obo2o234ungd3t8qjfcjrs3o6k-a-sites-opensocial.googleusercontent.com 4



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Apache2 BootCamp : Serving Dynamic Content with CGI Apache2 BootCamp : Serving Dynamic Content with CGI Presentation Transcript

    • #6 Day #2 Serving Dynamic Content with CGI Wildan Maulana wildan.m@openthinklabs.com http://workshop.openthinklabs.com
    • Overview● How the CGI protocol works● How to configure Apache to run CGI scripts, on both Unix and Windows● How to troubleshoot common errors
    • Common Gateway InterfaceSource : http://viu.eng.rpi.edu/
    • CGI ProtocolCERN HTTPd Server NCSA HTTPd Server Both provided mechanisms to invoke external programs and scripts to create dynamic content but incompatible The Solution The CGI 1.1 specification
    • CGI Operation● Apache receives a request and determines that it needs to be served by the CGI program● Apache starts an instance of the CGI program● Apache passes information about the request to the CGI● Apache receives the response from the CGI, optionally processes its headers and contents, and sends it to the client● The CGI program finishes and all resources associated with it are recalled by the operating system
    • CGI Environment VariablesVariable Name Variable DescriptionSERVER_NAME Hostname or IP address of the serverREQUEST_METHOD HTTP request method: HEAD, GET, POST, and so onREMOTE_ADDR Client IP addressCONTENT_TYPE MIME type of any client data being passed by a POST or PUT requestCONTENT_LENGTH Size of the client data
    • CGI Response● Location: Instructs Apache that the CGI is not going to answer the request and that the client should be redirected to the specified URL.● Status: This is not a valid HTTP header and it is not transmitted back to the client, but it indicates the HTTP status code for the request to Apache.● Content-Type: Specifies the type of data returned in the request. For example, if you are returning a Web page, the header value should be text/html.
    • Advantages and Disadvantages of CGI Scripts● Portability ● Performance● Simplicity ● Code and● Existing Code Presentation● Source Hiding● Memory Leaks
    • Configuring Apache
    • Configuring Apache CGI ContentScriptAliasScriptAlias /usr/local/apache2/cgi-bin/ /cgi-bin/
    • Configuring Apache Fine-Grained ControlSetHandler Directive# Any files accessed thru the /cgi-bin/ url will execute as CGI scripts.<Location “/cgi-bin/”> Options +ExecCGI SetHandler cgi-script<Location> Associating CGI Processing with File Extensions # Any files ending in .pl will be executed as CGI scripts <Files *.pl> Options +ExecCGI SetHandler cgi-script </Files> # Any files ending in .cgi in the /usr/local/apache2/htdocs/scripts # will be executed as CGI scripts AddHandler cgi-script .cgi <Directory “/usr/local/apache2/htdocs/scripts”> Options +ExecCGI </Directory>
    • Configuring Apache Action and ScriptAction image/gif /cgi-bin/process.cgiScript PUT /cgi-bin/upload.cgi
    • Configuring Apache CGI Security● Non Parse Headers (NPH) Scripts ● nph-example.cgi● Debugging CGI Execution ● ScriptLog ● ScriptLogLength ● ScriptLogBuffer
    • Unix ConfigurationTesting Shell Script CGIs
    • Unix Configuration Perl Installation● Preinstalled Perl #which perl perl -v● Installing Binaries ● Linux – Redhat : rpm -i perl*.rpm – Ubuntu : sudo apt-get install perl● Installing from Source http://www.perl.com/pub/a/language/info/software.html#sourcecode
    • Unix ConfigurationTesting Perl CGI Scripts
    • Windows Configuration● Testing Batch File CGIs● Perl on Windows ● http://www.activestate.com● Testing Perl Scripts
    • Enhancing Your CGI Performance● mod_perl● FastCGI
    • Common CGI Problems● Forbidden Error ● Filesystem Permissions ● CGI Execute Permissions● Internal Server Error ● Program Permissions ● Interpreter Location ● Malformed Headers● Other Causes● Source Code in the Browser
    • Q&Ahttp://workshop.openthinklabs.com/resources
    • Reference● Daniel Lopez Ridruezo; SAMS Teach Yourself Apache2 in 24 Hours, SAMS Publishing, 2002 (Buy this book on Amazon)