Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

where to place the .pl fro cgi script

by phemal (Sexton)
on Oct 25, 2006 at 04:56 UTC ( #580486=perlquestion: print w/ replies, xml ) Need Help??
phemal has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have started learning cgi scripting. I know the hello world program, but i am not aware where to place the hello.pl so that when i go to web browser and type http://servername/cgi-bin/hello.pl i should get the hello world output. Thanks Hemal

Comment on where to place the .pl fro cgi script
Re: where to place the .pl fro cgi script
by McDarren (Abbot) on Oct 25, 2006 at 05:02 UTC
Re: where to place the .pl fro cgi script
by shmem (Canon) on Oct 25, 2006 at 05:05 UTC
    Read the documentation of your web server program. It must be placed in a directory where it can be found by the web server. That directory must be marked as containing executable CGI (common gateway interface) programs.

    --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}
Re: where to place the .pl fro cgi script
by jonnyfolk (Vicar) on Oct 25, 2006 at 09:24 UTC

    The answers previously given are quite correct, of course, but the precise answer to your question is that hello.pl must be placed in the directory cgi-bin.

    Typically this will be found in the public_html directory, but is sometimes not so you may have to look around for it

    You also may need to change the permissions on the file to 755 (normally this can be done using you ftp client) and if you are viewing from a browser an html header print "Content-type: text/html\n\n"; before your print 'hello world'; statement will probably be necessary.

    Should the script not function after all this come back to us and we'll try to be of more help.

      but the precise answer to your question is that hello.pl must be placed in the directory cgi-bin

      Er... no. The precise answer is that hello.pl must be placed in whatever directory the configuration of the web server has mapped to the URL /cgi-bin/. This is often a directory called cgi-bin but without examining the web server configuration files you can't be 100% sure. It's possible that it's not mapped onto any directory at all.

      Typically this will be found in the public_html directory

      Well, only on servers that have user directories enabled. And even then only on ones that allow individual users to have cgi-bin directories. That's pretty rare in my experience.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        davorg, you have to get out more. If you go to any of the millions of web hosting sites on the internet you will have trouble finding one that doesn't provide a cgi-bin.

        I had the feeling the the OP was looking for a pointer and if my reply helped then that's good and if not tant pis!

      the precise answer to your question is that hello.pl must be placed in the directory cgi-bin.

      No, that's a common configuration, but not universal, on my system this is called "cgi" not "cgi-bin". The precise answer is the one you get after reading the documentation for your webserver.

      Typically this will be found in the public_html directory, but is sometimes not so you may have to look around for it

      On my system 'public_html' is 'pages', and 'cgi' is a sibling, not a child. You shouldn't have to "look around for it" though, the aforementioned documentation should tell you.

      You also may need to change the permissions on the file to 755

      Hopefully the system will be set up so that world doesn't need access and you can limit execute permission to the group.

      (normally this can be done using you ftp client)

      Although hopefully you are using sftp, rsync over ssh, or some other means of transfering files that doesn't result in passwords being sent in clear text.

      and if you are viewing from a browser an html header print "Content-type: text/html\n\n"; before your print 'hello world'; statement will probably be necessary.

      Would it qualify as a CGI script if it didn't output a Content-type header?

      Either way, printing out the content-type directly instead of using a module (such as CGI.pm) probably isn't the way to go.

      I've managed/supported quite a few servers over the years (dating back to Netscape Server 2, and AOL's NaviServer), and for this sort of question, it's best not to assume anything about their server configuration.

      The system may have all items ending in '.cgi' mapped to mod_cgi in apache, which allows them to place the file anywhere that the webserver can see it, provided it has the correct extension and permissions.

      If they're using CGIwrap (which I suggest for multi-user systems with cgi access), then the cgi-bin directory should not be in public_html, as it may allow folks to read your scripts if you don't have the permissions set correctly. (and in this case, set correctly is not 0755, it's 0500).

      I would assume that whatever server is either using virtual hosts, or is not multi-use, based on the URL that was given, but know that there are many, many different configurations for such things, and so not to guess the directories. (eg, MacOS X places CGIs in /Library/Webserver/CGI-Executables, even though it maps to http://host/cgi-bin/

      ...

      So, my suggestion would be -- if you're using an ISP or hosting service -- contact them. They're the only ones who would know the configuration of their system. If you're hosting your own system, we'll need more information -- is it a default install? If so, what OS?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://580486]
Approved by shmem
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-09-20 21:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (163 votes), past polls