manishrathi has asked for the wisdom of the Perl Monks concerning the following question:

How does the server know that a CGI script is to be ececuted for renderin output ? Is it because of its location in the cgi/bin directory ? or is it because of the .cgi extension ?
We can change the default location of cgi scripts. So in case of different location of CGI script, how would the server know whether to execute the script or render it without execution ?
If its the extension that instructs the server to execute the ci script, then what happens if a cgi script has .pl extension. As cgi script can have any extension, in that case how wd the server know whether to execute the script or render it as is ?

Replies are listed 'Best First'.
Re: execution of CGI scripts
by davido (Cardinal) on Oct 23, 2009 at 06:41 UTC

    The answer you seek is specific to the web server you're operating under. In general, the method of distinguishing executable files is configurable, but the configuration must be done with respect to the web server. Apache has one way of doing it, other web servers have other ways. And yes, you may set the server to find CGI scripts in a particular directory, or with a specific extension.

    So check with your server's administrator, or if you are the administrator, check in the manual pages of the web server you're administering. We love to help with Perl questions, but this is a web-server question, and we're not really all that well equipped to provide support for all the various brands and versions of web servers there out there in the world.


    Dave

      Actually, Apache has two ways of doing it:
      ScriptAlias /cgi-bin/ "/path/to/cgi-bin/"
      will cause all files accessed via /cgi-bin/ in the URI to be executed as CGI processes, as the OP theorized.
      AddHandler cgi-script .cgi
      will cause all files whose names end with .cgi to be executed as CGI processes, regardless of their location. This could easily be modified to cause CGI execution of, say .pl files if a server admin so desired.