There are two ways to handle CGI scripts, SetHandler
and AddHandler
.
SetHandler cgi-script
applies to all files in a given context, no matter how they are named, even index.html
or style.css
.
AddHandler cgi-script .pl
is similar, but applies to files ending in .pl
, in a given context. You may choose another extension or several, if you like.
Additionally, the CGI module must be loaded and Options +ExecCGI
configured. To activate the module, issue
a2enmod cgi
and restart or reload Apache. Finally, the Perl CGI script must be executable. So the execute bits must be set
chmod a+x script.pl
and it should start with
#! /usr/bin/perl
as its first line.
When you use SetHandler
or AddHandler
(and Options +ExecCGI
) outside of any directive, it is applied globally to all files. But you may restrict the context to a subset by enclosing these directives inside, e.g. Directory
<Directory /path/to/some/cgi-dir>
SetHandler cgi-script
Options +ExecCGI
</Directory>
Now SetHandler
applies only to the files inside /path/to/some/cgi-dir instead of all files of the web site. Same is with AddHandler
inside a Directory
or Location
directive, of course. It then applies to the files inside /path/to/some/cgi-dir, ending in .pl
.