in reply to Enabling CGI Script from Apache's htdocs directory

Normally cgi-bin is not within the htdocs directory. Can you copy your script to /usr/local/apache/cgi-bin? If so, will it run from there? It all depends on your apache configuration (/usr/local/apache/conf/httpd.conf).

-derby
  • Comment on Re: Enabling CGI Script from Apache's htdocs directory

Replies are listed 'Best First'.
Re^2: Enabling CGI Script from Apache's htdocs directory
by monkfan (Curate) on Apr 06, 2007 at 14:08 UTC
    Hi,

    I've copied my hello.cgi to this directory /usr/local/apache/cgi-bin. And it works, thanks.

    But my intention is to really access the cgi-bin from my htdocs/ directory. Like this:
    htdocs-- |_Test |_cgi-bin/ | |_Webap1 |_ cgi-bin/ | |_Webap2 |_ cgi-bin/
    Because there will be many webapps I need to build (hence many subdirectory other than "Test"). I've tried to modified the following httpd.conf entry:
    #ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/" # into ScriptAlias /cgi-bin/ "/usr/local/apache/htdocs/cgi-bin/
    But still unable to get it working. How can I enable it from this httpd.conf below?

    Regards,
    Edward

      Check out the howto.

      -derby

      update: I'm not a apache 2.2 expert by anymeans but I think you're going to want something like this in your httpd.conf:

      <Directory /usr/local/apache/htdocs/*/cgi-bin> Options +ExecCGI </Directory>
      That being said ... I think one of the drawbacks to your approach is your exposing way too much of your underlying architecture. User's are going to see something like this:
      http://bioinfo-z.comp.nus.edu.sg/Test/cgi-bin/foo http://bioinfo-z.comp.nus.edu.sg/WebApp1/cgi-bin/bar http://bioinfo-z.comp.nus.edu.sg/WebApp2/cgi-bin/baz
      I think a better approach would be to either use virtual servers:
      http://test.comp.nus.edu.sg/cgi-bin/foo http://webapp1.comp.nus.edu.sg/cgi-bin/bar http://webapp2.comp.nus.edu.sg/cgi-bin/baz
      Or something like CGI::Application
      http://bioinfo-z.comp.nus.edu.sg/cgi-bin/test?mode=foo http://bioinfo-z.comp.nus.edu.sg/cgi-bin/webapp1?mode=bar http://bioinfo-z.comp.nus.edu.sg/cgi-bin/webapp2?mode=baz

      Because there will be many webapps I need to build (hence many subdirectory other than "Test"). I've tried to modified the following httpd.conf entry:
      #ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/" # into ScriptAlias /cgi-bin/ "/usr/local/apache/htdocs/cgi-bin/

      Note that there's the ending quote missing. But this modification would allow you to access scripts in /usr/local/apache/htdocs/cgi-bin/hello.cgi as

      http://bioinfo-z.comp.nus.edu.sg/cgi-bin/hello.cgi

      Try

      ScriptAlias /Test/cgi-bin/ /usr/local/apache/htdocs/Test/cgi-bin/ ScriptAlias /Webap1/cgi-bin/ /usr/local/apache/htdocs/Webap1/cgi-bin/ ScriptAlias /Webap2/cgi-bin/ /usr/local/apache/htdocs/Webap2/cgi-bin/

      inside your <IfModule alias_module></IfModule> block.

      You could also omit the cgi-bin part

      ScriptAlias /Test/ /usr/local/apache/htdocs/Test/cgi-bin/ ScriptAlias /Webap1/ /usr/local/apache/htdocs/Webap1/cgi-bin/ ScriptAlias /Webap2/ /usr/local/apache/htdocs/Webap2/cgi-bin/

      to access e.g /usr/local/apache/htdocs/Webap1/cgi-bin/hello.cgi as

      http://bioinfo-z.comp.nus.edu.sg/Webap1/hello.cgi

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}