Common Gateway Interface (CGI)

Demo

  • Shell(cgi.sh):

    #!/bin/bash
    
    echo "Content-type: text/plain"
    echo
    echo "Hello world!"
    echo
    echo "Environment variables:"
    echo
    echo $(env)
  • Python(cgi.py):

    #!/usr/bin/python
    
    import os
    
    print "Content-type: text/html"
    print
    print "<p>Hello world!"
    print "<p>Environment variables:"
    print "<p>"
    for v in os.environ:
        print "%s=%s<br>" % (v, os.environ[v])

Test

By default, the default cgi-bin directory of apache is /var/www/cgi-bin. So copy the cgi scripts into that directory and invoke them in the browser:

FastCGI

Download fastcgi module source and extract. then do:

$ cd <mod_fastcgi_dir>
$ cp Makefile.AP2 Makefile
$ make top_dir=/usr/lib/httpd
# make top_dir=/usr/lib/httpd install

Add the following lines to Apache httpd configure file:

LoadModule fastcgi_module modules/mod_fastcgi.so
FastCgiIpcDir /tmp

This is not enough, we need a extra step:

$ chmod 777 -R /tmp/dynamic

See the fastcgi permission error thread.

None: CGI (last edited 2009-10-08 07:40:05 by ZhigangWang)