1

I want to be able to run cgi scripts from other locations besides /var/www/cgi-bin, examples:

/var/www/folder1/cgi-bin
/var/www/folder2/cgi-bin
/var/www/folder3/cgi-bin

How do I go about configuring the server to do this?

EDIT: This is to run cgi scripts from a website on my personally hosted webserver.

Anthony Miller
  • 457
  • 3
  • 6
  • 19

2 Answers2

1

ScriptAlias is your uncle.

From: http://httpd.apache.org/docs/2.2/mod/mod_alias.html#scriptalias

Description:    Maps a URL to a filesystem location and designates the target as a CGI script
Syntax: ScriptAlias URL-path file-path|directory-path
Context:    server config, virtual host
Status: Base
Module: mod_alias

The ScriptAlias directive has the same behavior as the Alias directive, except that in addition it marks the target directory as containing CGI scripts that will be processed by mod_cgi's cgi-script handler. URLs with a case-sensitive (%-decoded) path beginning with URL-path will be mapped to scripts beginning with the second argument, which is a full pathname in the local filesystem.
Example:

ScriptAlias /cgi-bin/ /web/cgi-bin/

A request for http://example.com/cgi-bin/foo would cause the server to run the script /web/cgi-bin/foo. This configuration is essentially equivalent to:

Alias /cgi-bin/ /web/cgi-bin/
<Location /cgi-bin >
SetHandler cgi-script
Options +ExecCGI
</Location> 
Alien Life Form
  • 2,309
  • 2
  • 21
  • 32
  • Is there a specific configuration file I'm supposed to be looking at? – Anthony Miller Oct 21 '11 at 16:36
  • I edit httpd.conf, there's the default entry of: `/cgi-bin/ "/var/www/cgi-bin/"` I create an additional entry below it: `/cgi-bin/ "/var/www/folder1/cgi-bin/"` I restart the httpd and I still do not have access to my cgi script. However it still works if ran from /var/www/cgi-bin/ – Anthony Miller Oct 21 '11 at 16:43
1

There are two ways to accomplish this:

1) Setup virtualhosts, and under each virtualhost, specify ScriptAlias /cgi-bin/ "/your/location"

2) Create sub-folders under /var/www/cgi-bin and use the sub-folders to link to them, however with this method, you cannot leave the /var/www/cgi-bin directory tree.

Anthony Miller
  • 457
  • 3
  • 6
  • 19