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

First Script

by Smash8 (Initiate)
on Jul 17, 2000 at 21:13 UTC ( [id://22866]=perlquestion: print w/replies, xml ) Need Help??

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

Here is my first script ever and it is already not working:

#!/usr/local/bin/perl

use CGI;

$query = new CGI;

print $query->header;

print "<html><head><title>A test</title></head>\n";
print "<body>The test was successful.</body></html>";

This code is run at http://www.adamtarkowski.com/counter.htm
When I run this, I get a 403 (Forbidden). Any ideas?

Replies are listed 'Best First'.
(jjhorner) First Script
by jjhorner (Hermit) on Jul 17, 2000 at 21:26 UTC

    A few points for a beginner:

    • Check file permissions. Make sure you have the read/execute bit set for all.
    • Use '-w' and 'strict'. It will make debugging more complex scripts easier
    • use '-T' to make sure you aren't tainting your script.
    • Read maverick's post above. Good points.
    • Make sure your directory (in your httpd.conf file) has ExecCGI as an option.
    • It looks as though you are trying to call it from /cgi-bin, so it should be accessible.
    • Let us know if any of this fixed it.
    J. J. Horner
    Linux, Perl, Apache, Stronghold, Unix
    jhorner@knoxlug.org http://www.knoxlug.org/
    
      jjhorner made some great points above. I think he likely hit it on the head with respect to the ExecCGI option in your httpd.conf file. Go to www.apache.org to read up on documentation on this config file. Your other temporary fix (assuming your current httpd.conf allows it) is to override the global access directives with your own .htaccess file in the same dir as your script with a single line that says
      Options ExecCGI
      But this will only fix it for that directory, like I said. You'll also want to make sure your httpd.conf contains a handler for the .cgi and .pl scripts. :-)
Re: First Script
by maverick (Curate) on Jul 17, 2000 at 21:20 UTC
    this looks like a permission problem.
    things to check:
    • you have the correct path the perl
    • the script is executable. chmod 755 my_script.pl
    • the script is in a directory that is accessable by the web server
    • the script is in a directory that is setup as a CGI directory by the web server.
    Try running the script from the command line. If it runs, then the problem is most likely in the web server's configuration.

    /\/\averick

RE: First Script (Ozymandias: File permissions)
by Ozymandias (Hermit) on Jul 17, 2000 at 21:17 UTC
    Permissions error. Make sure the webserver has permission to execute the script.

    For a simple script like this, just give everyone read/execute permissions. Keep in mind that CGI security is normally very complex, and you're going to want to be much more careful normally. But for now (assuming Unix/Linux) just execute this as the owner of the script:

    chmod 755 <filename>

    - email Ozymandias
Re: First Script
by btrott (Parson) on Jul 17, 2000 at 21:27 UTC
Re: First Script
by mrmick (Curate) on Jul 17, 2000 at 23:13 UTC
    Even though this is not a Perl-specific response, here is a list of http ErrorDocument types:

    Where type is one of:

    • 302 - REDIRECT
    • 400 - BAD_REQUEST
    • 401 - AUTH_REQUIRED
    • 403 - FORBIDDEN
    • 404 - NOT_FOUND
    • 500 - SERVER_ERROR
    • 501 - NOT_IMPLEMENTED
    Incidentally, I tried your code and it works fine. If you uploaded the file from a PC, you may want to check for control M's. This has caught me in the past (before I learned vi). You will see the following in your file if this is the case:
    ^M
    Mick
      Mick, did you run the code yourself (if so, could you explain how) or did you run it off my website? Thanks
        Well, if you are able, run the script from the command line. If your program fails to compile, that may be the problem.

        Quick checklist:

        • Correct permissions.
        • Correct shebang line
        • In the correct directory?
        • Is a particular extension required (i.e., do you have myprog.pl instead of myprog.cgi)?
        Another thing to do (in test only, don't use this for production), is to add the following line to the script:
        use CGI::Carp qw(fatalsToBrowser);
        If your script actually gets as far as compiling and the program tries to run, this will output the error messages to your browser, which aids debugging. Make sure that you take this out when you move the code to production as there is no sense in giving hackers additional information.

        From what you are describing, it sounds like the problem is not with your code, but with the configuration. You have your code in the wrong place or something.

        Is there any chance that you made corrections to your code that you forgot to upload to the server?

        I ran it (without any modifications) on my intranet webserver. It's an HP-UX running Netscape Suitespot server, if that helps. :-)

        Mick
RE: First Script
by wardk (Deacon) on Jul 18, 2000 at 02:03 UTC
    make sure the file has proper permissions for reading and executing.
    
    chmod 755 <filename>
    
    should make it executable and restrict only you from editing.
    
RE: First Script
by Smash8 (Initiate) on Jul 17, 2000 at 21:47 UTC
    I'm really sorry to keep pestering everyone with my simple problem, but this is my first time every trying to get a script to work. Everyone posted a lot of helpful information for someone with a vague idea of perl, but as I said, I am very new. I think the problem is definately in the access privliges, which seems to be chmod (????). How do I implement chmod to change access? Or is it just a problem my hosting service needs to take care of? Thanks a lot
      Your provider might have to do it.

      If you can log in using a shell account, do so. Go to the directory where the script is located, and execute the command (assuming the filename is script.pl) chmod 755 script.pl And that's all you have to do. If you can't do that, then your provider will have to explain how to do it.

      Also, make sure your script is in the CGI directory for the site. Your provider will tell you where that is.

      - Ozymandias

        I really appreciate all the help and patience everyone has been throwing my way.
        If you look at the past messages, I was unable to get my script ot work and before that was due to me not giving access to the file. Now I am getting a 500 (Server error) problem.

        #!/usr/bin/perl

        is the correct directory (i checked with my system administrator) so i'm not sure where I'm going wrong. Again, I appreciate help from everyone willing to help a new guy out. Thanks a lot.

      You have to have telnet access to the box that houses your script. You simply telnet there and run chmod 755 <filename>.

      Apterigo
Re: First Script
by Anonymous Monk on Jul 18, 2000 at 04:33 UTC
    if you dont have telnet access to your site then a robust FTP program like WS_FTP or Bullet Proof FTP etc. will allow you to change permissions.
Re: First Script
by frankus (Priest) on Jul 18, 2000 at 18:22 UTC
    Blimey, my first script was :
    print "Hello World.\n";
    
    

    Brother Frankus.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-28 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found