ExecCGI
I'm guessing your cgi-bin
directory is not ScriptAlias
'ed, in which case you will need to use the ExecCGI
option in addition to setting a handler:
AddHandler cgi-script .cgi .pl
Options +ExecCGI
Also make sure that Apache has execute permissions for your scripts. See Configuring Apache to permit CGI for details.
#include virtual
Also, you should use the SSI command #include virtual
instead of #exec cgi
:
<!--#include virtual="/cgi-bin/test.pl" -->
According to the Apache manual:
The use of #include virtual
is almost always prefered to using either #exec cgi
or #exec cmd
. The former (#include virtual
) uses the standard Apache sub-request mechanism to include files or scripts. It is much better tested and maintained.
What's worse, #exec
can be used to run arbitrary code on your web server. It's actually best to disable it completely:
Options +IncludesNOEXEC
#include
also allows you to pass arguments to your CGI via the query string, e.g.
<!--#include virtual="/cgi-bin/test.pl?arg1=foo&arg2=bar" -->
which you can't do with #exec
.
Note that the argument you pass to #include virtual
is a URL relative to the current document, not a file path.
I would recommend reading Apache's Introduction to Server Side Includes if you haven't already.
XBitHack
Finally, instead of requiring SSI files to have a special file extension (.shtml
), I prefer to use the XBitHack
directive:
XBitHack on
Any text/html
file with the user execute bit set will be parsed for SSI. This means you don't have to rename files (possibly breaking links or users' bookmarks) when you want to add SSI to them.
Putting it all together, I would set .htaccess
like this:
AddHandler cgi-script .cgi .pl
Options +ExecCGI +IncludesNOEXEC
XBitHack on