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.
Reference
- http://www.w3.org/CGI/
- http://en.wikipedia.org/wiki/Common_Gateway_Interface
- http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface
- http://wsgi.org/
- PEP 333: Python Web Server Gateway Interface v1.0: http://www.python.org/dev/peps/pep-0333/
- http://en.wikipedia.org/wiki/Simple_Common_Gateway_Interface
- SCGI specification: http://python.ca/scgi/protocol.txt
- http://en.wikipedia.org/wiki/FastCGI
- http://www.fastcgi.com/
- Python Paste: http://pythonpaste.org/
- WebOb: http://pythonpaste.org/webob
