CGI: Introduction: Difference between revisions

m
Minor cleanup
m (More cleanup.)
m (Minor cleanup)
Line 245: Line 245:


==Configuring Apache CGI - Overview==
==Configuring Apache CGI - Overview==
The following provides a general overview of how to configuring Apache to run CGI scripts. In order to run CGI programs, Apache requires configuration directives to permit CGI execution. You can use one of the following methods to permit CGI execution.
The following provides a general overview of how to configuring Apache to run CGI scripts. In order to run CGI programs, Apache requires configuration directives to permit CGI execution.  


'''''Note'':''' All three methods require the mod_cgi module to be enabled as shown below:
'''''Note'':''' All three methods require the mod_cgi module to be enabled as shown below:
Line 251: Line 251:
LoadModule cgi_module modules/mod_cgi.so
LoadModule cgi_module modules/mod_cgi.so
</pre>
</pre>
You can select one of the following methods to permit CGI execution.
===Method 1: ScriptAlias===
===Method 1: ScriptAlias===
The '''ScriptAlias''' directive tells Apache that a particular directory is set aside for CGI programs. Apache now assumes every file in this directory is a CGI program. When a page from this folder is requested, Apache will attempt to execute it using the appropriate program.
The '''ScriptAlias''' directive tells Apache that a particular directory is set aside for CGI programs. Apache now assumes every file in this directory is a CGI program. When a page from this folder is requested, Apache will attempt to execute it using the appropriate program.
Line 274: Line 277:


===Method 3: .htaccess===
===Method 3: .htaccess===
Using '''.htaccess''' files allow you to set configuration directives on a per-directory basis. Apache looks in a folder from which it is serving for this file and applies the directives found. To enable the use of .htaccess files, edit the Apache configuration files as follows:
Using '''.htaccess''' files allow you to set configuration directives on a per-directory basis. Apache looks for this file in a folder from which it is serving and applies the directives found. To enable the use of .htaccess files, edit the Apache configuration files as follows:


Change or add the AllowOverride directive in a specific folder directive; for example, www as shown below:
Change or add the AllowOverride directive in a specific folder directive; for example, www as shown below:
Line 297: Line 300:
Options +FollowSymlinks
Options +FollowSymlinks
</pre>
</pre>
Which tells Apache that execution of CGI programs is permitted in this folder.
This tells Apache that execution of CGI programs is permitted in this folder.


'''''Note'':''' All of The Uniform Servers have been pre-configured to allow the use of .htaccess files.
'''''Note'':''' All of The Uniform Servers have been pre-configured to allow the use of .htaccess files.


===AddHandler===
===AddHandler===
Using either of the above methods Apache will attempt to execute every file as a CGI script. This includes files such as css and images. Clearly these are not CGI scripts and would produce errors when executed. To avoid this you need to inform the server what files are genuine CGI scripts by using the AddHandler directive.
Using either of the above methods, Apache will attempt to execute every file as a CGI script. This includes files such as css and images. Clearly these are not CGI scripts and would produce errors when executed. To avoid this you need to inform the server what files are genuine CGI scripts by using the AddHandler directive.
<pre>
<pre>
AddHandler cgi-script .cgi .pl .vbs
AddHandler cgi-script .cgi .pl .vbs
Line 340: Line 343:


==Where to next==
==Where to next==
 
The [[CGI: VBScript CGI|next page]] details how to format a VBScript for running as a CGI script.
[[CGI: VBScript CGI|Next page]] details how to format a VBScript for running as a CGI script.


----
----