http://www.jdon.com/idea/cgi.htm
The Common Gateway Interface (CGI) is a standard protocol that defines how webserver software can delegate the generation of webpages to a console application. Such applications are known as CGI scripts; they can be written in any programming language, although scripting languages are often used.
Drawbacks
Calling a command generally means the invocation of a newly created process. Starting up the process can take up much more time and memory than the actual work of generating the output, especially when the program still needs to be interpreted or compiled. If the command is called often, the resulting workload can quickly overwhelm the web server.
The overhead involved in interpretation may be reduced by using compiled CGI programs, such as those in C/C++, rather than using Perl or other scripting languages. The overhead involved in process creation can be reduced by solutions such as FastCGI, or by running the application code entirely within the webserver using special extension modules.
Alternatives
Several approaches can be adopted for remedying this:
- The popular Web servers developed their own extension mechanisms that allows third-party software to run inside the web server itself, e.g. Apache modules, Netscape NSAPI plug-ins,IIS ISAPI plug-ins.
- Simple Common Gateway Interface or SCGI
- FastCGI allows a single, long-running process to handle more than one user request while keeping close to the CGI programming model, retaining the simplicity while eliminating much of the overhead CGI incurs by creating a new process for each request. Unlike converting an application to a web server plug-in, FastCGI applications remain independent of the web server.
Alternatives
PHP
JSP
ASP
Python: The Web Server Gateway Interface defines a simple and universal interface between web servers and web applications or frameworks for the Python programming language.
Hello, CGI
apache in redhat
http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/index.html
http://httpd.apache.org/docs/2.2/howto/cgi.html
1. start up apache
/etc/rc.d/init.d/httpd start
2. write cgi script, under ScriptAlias dir
Default cgi script is put under /var/www/cgi-bin
/etc/httpd/conf/httpd.conf
ScriptAlias /cgi-bin/ /var/www/cgi-bin
Perl script: hello.cgi
Shell script: getdate.cgi
File permissions
Remember that the server does not run as you. That is, when the server starts up, it is running with the permissions of an unprivileged user - usually nobody, or www - and so it will need extra permissions to execute files that are owned by you. Usually, the way to give a file sufficient permissions to be executed by nobody is to give everyone execute permission on the file:
chmod a+x first.pl
Also, if your program reads from, or writes to, any other files, those files will need to have the correct permissions to permit this.
3. request through browser
http://host/cgi-bin/hello.cgi
http://host/cgi-bin/getdate.cgi
Directory