Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

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> 
share|improve this answer
    
Is there a specific configuration file I'm supposed to be looking at? –  Mechaflash 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/ –  Mechaflash Oct 21 '11 at 16:43
add comment
up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.