<modulelist>
<module>mod_alias</module>
<module>mod_cgi</module>
+ <module>mod_cgid</module>
</modulelist>
<directivelist>
<p>The CGI (Common Gateway Interface) defines a way for a web
server to interact with external content-generating programs,
which are often referred to as CGI programs or CGI scripts. It
- is the simplest, and most common, way to put dynamic content on
- your web site. This document will be an introduction to setting
+ is a simple way to put dynamic content on
+ your web site, using whatever programming language you're most
+ familiar with. This document will be an introduction to setting
up CGI on your Apache web server, and getting started writing
CGI programs.</p>
</section>
directive has not been commented out. A correctly configured directive
may look like this:
- <example>
+ <highlight language="config">
+ LoadModule cgid_module modules/mod_cgid.so
+ </highlight>
+
+
+ On Windows, or using a non-threaded MPM like prefork, A correctly
+ configured directive may look like this:
+
+ <highlight language="config">
LoadModule cgi_module modules/mod_cgi.so
- </example></note>
+ </highlight></note>
+
<section id="scriptalias">
<title>ScriptAlias</title>
<p>The <directive module="mod_alias">ScriptAlias</directive>
directive looks like:</p>
- <example>
- ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/
- </example>
+ <highlight language="config">
+ScriptAlias "/cgi-bin/" "/usr/local/apache2/cgi-bin/"
+ </highlight>
<p>The example shown is from your default <code>httpd.conf</code>
configuration file, if you installed Apache in the default
file, to specify that CGI execution was permitted in a particular
directory:</p>
- <example>
- <Directory /usr/local/apache2/htdocs/somedir><br />
- <indent>
- Options +ExecCGI<br />
- </indent>
- </Directory>
- </example>
+ <highlight language="config">
+<Directory "/usr/local/apache2/htdocs/somedir">
+ Options +ExecCGI
+</Directory>
+ </highlight>
<p>The above directive tells Apache to permit the execution
of CGI files. You will also need to tell the server what
files with the <code>cgi</code> or <code>pl</code> extension as CGI
programs:</p>
- <example>
+ <highlight language="config">
AddHandler cgi-script .cgi .pl
- </example>
+ </highlight>
</section>
<section id="htaccess">
<code>.cgi</code> in users' directories, you can use the
following configuration.</p>
- <example>
- <Directory /home/*/public_html><br/>
- <indent>
- Options +ExecCGI<br/>
- AddHandler cgi-script .cgi<br/>
- </indent>
- </Directory>
- </example>
+ <highlight language="config">
+<Directory "/home/*/public_html">
+ Options +ExecCGI
+ AddHandler cgi-script .cgi
+</Directory>
+ </highlight>
<p>If you wish designate a <code>cgi-bin</code> subdirectory of
a user's directory where everything will be treated as a CGI
program, you can use the following.</p>
- <example>
- <Directory /home/*/public_html/cgi-bin><br/>
- <indent>
- Options ExecCGI<br/>
- SetHandler cgi-script<br/>
- </indent>
- </Directory>
- </example>
+ <highlight language="config">
+<Directory "/home/*/public_html/cgi-bin">
+ Options ExecCGI
+ SetHandler cgi-script
+</Directory>
+ </highlight>
</section>
file called <code>first.pl</code>, and put it in your
<code>cgi-bin</code> directory.</p>
- <example>
- #!/usr/bin/perl<br />
- print "Content-type: text/html\n\n";<br />
- print "Hello, World.";
- </example>
+ <highlight language="perl">
+#!/usr/bin/perl
+print "Content-type: text/html\n\n";
+print "Hello, World.";
+ </highlight>
<p>Even if you are not familiar with Perl, you should be able
to see what is happening here. The first line tells Apache
interpreter (often <code>perl</code>) indicated in the first
line of your CGI program, which will look something like:</p>
- <example>
+ <highlight language="perl">
#!/usr/bin/perl
- </example>
+ </highlight>
<p>Make sure that this is in fact the path to the
interpreter.</p>
<a href="../env.html">add your own environment variables</a>
to the basic ones provided by default.</p>
- <example>
- #!/usr/bin/perl<br />
- print "Content-type: text/html\n\n";<br />
- foreach $key (keys %ENV) {<br />
- <indent>
- print "$key --> $ENV{$key}<br>";<br />
- </indent>
- }
- </example>
+ <highlight language="perl">
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+print "Content-type: text/html\n\n";
+foreach my $key (keys %ENV) {
+ print "$key --> $ENV{$key}<br>";
+}
+ </highlight>
</section>
<section id="stdin">
have found a problem in the Apache source code.</p>
</section>
</manualpage>
-