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

Hello Monks,

I am learning cgi scripting. so I installed apache in windows and configured httpd.conf. When I run the first sample program to print out system environment variables, I got the source code in brower.

can you please help in this

thanks,

Siva

  • Comment on source code of cgi script directly opens in browser

Replies are listed 'Best First'.
Re: source code of cgi script directly opens in browser
by ikegami (Patriarch) on Mar 12, 2007 at 07:59 UTC

    That isn't a Perl problem. Your web server isn't configured to do what you want it to do. It hasn't been told to treat the file as a CGI script.

    If you want to treat all .cgi files in a directory and subdirectories as CGI scripts:

    <Directory /some/dir/htdocs/> Options +ExecCGI AddHandler cgi-script .cgi </Directory>

    If you want to treat all files in a directory and subdirectories as CGI scripts:

    <Directory /some/dir/cgi-bin/> Options +ExecCGI SetHandler cgi-script </Directory>

    There's also ScriptAlias.

Re: source code of cgi script directly opens in browser
by hangon (Deacon) on Mar 12, 2007 at 09:47 UTC

    Even though you're just learning cgi, its a good time to start thinking about security. The first thing you should do is be sure that your script directory is outside of your html document tree, and use ScriptAlias as mentioned by ikegami. You might also want to read this node on cgi security.

    # this /path/to/apache | +---/cgi-bin | +---/htdocs # not this /path/to/apache | +---/htdocs | +---/cgi-bin # add to httpd.conf ScriptAlias /cgi-bin/ "/path/to/apache/cgi-bin/"
Re: source code of cgi script directly opens in browser
by asz (Pilgrim) on Mar 12, 2007 at 08:04 UTC