By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,372 Members | 1,906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,372 IT Pros & Developers. It's quick & easy.

why is my site giving me a 500 error?

P: 2
Im a student of ryerson university, Im trying to create a simple website for my assignment and Im getting a 500 internal server error

my code compiles and doesnt seem to have any syntax errors but I cant seem to figure out what is wrong with it, any help will be great, here is the code I have so far
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use CGI':standard';
  3. use strict;
  4.  
  5. print "Content-type: text/html\n\n";
  6.  
  7. #name of the user
  8. my $name; 
  9. #obtaining the name from a cookie
  10. $name = cookie('name'); 
  11.  
  12.  
  13. print <<HTML;
  14.    <html>
  15.    <head>
  16.       <title> CPS 530 Assignment 1 </title>
  17.       <link rel="stylesheet" type="text/css" href="/home/jwong/public_html/assignment1/style.css" />
  18.    </head>
  19.    <body>
  20.    <br><br>
  21.    <h1> Welcome to Jay\'s photo upload </h1>
  22. HTML
  23.  
  24. #if there is a user name from the cookie
  25. if ($name) {
  26.    print <<HTML;
  27.          <p> Pleased to see you\'ve returned, $name</p><br><br>
  28.          <a href="http://www.scs.ryerson.ca/~jwong/assignment1/a1.html"><img src="nextbutton.gif" alt="next page" /></a>
  29.       </body>
  30.       </html>
  31. HTML
  32. }
  33.  
  34. #if this is a new vistior
  35. else {
  36.    print <<HTML;
  37.          <p> This must be your first time here, please tell me your name </p>
  38.          <p> Name: <form action="cookie.cgi" method="post"><input type="text" name="name"><input type="submit" value="done"></form></p>
  39.       </body>
  40.       </html>
  41. HTML
  42. }
  43.  
Nov 10 '08 #1
Share this Question
Share on Google+
13 Replies


KevinADC
Expert 2.5K+
P: 4,059
The code looks like it should run OK, so something else is wrong. Some possibilities:

the shebang line is wrong
not uploaded in ASCII mode
permissions not correct
Nov 10 '08 #2

P: 2
The code looks like it should run OK, so something else is wrong. Some possibilities:

the shebang line is wrong
not uploaded in ASCII mode
permissions not correct
well the shebang line is pretty much a copy paste job from my professor's notes, and im not sure what you mean by uploading in ascii mode, if you can give me a simple walkthrough on what you mean there, that would be great, (dont think I saw much on that on the lecture slides) and as for permissions, I think I did it right, the cgi-bin folder is set to 711, and the cgi files are set to 644 and i've tried 755. i've even tried it as 777 just as a test and still ended up with the same results

so im guessing the ascii mode portion is what it could be since I've never tested that. i'll just need some kinda guide through how I would test this
Nov 10 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
When you transfer the perl script from your computer to the server using an FTP program, you can transfer in ASCII (text files) or binary (images and executables) mode. Read the help files of the FTP application you are using to detemine how to change the transfer mode.

Almost all FTP applications will change the line endings when a file is transferred in ASCII (or text) mode from the local line endings to the line endings of the remote server. For example, if you write the perl program on Windows the line endings are \r\n and if you tranfer that to a Unix server the script would not work because of the carraige returns (\r) but if you use an FTP application almost all of them know to change the line endings to whatever ther remote servers operating system uses, \n for Unix.

Some, not many, editors also allow you to save a file with line endings of many operating systems. You can check your editor to see if there is an option to save as Unix or Linux or whatever.
Nov 10 '08 #4

Ganon11
Expert 2.5K+
P: 3,652
If you're porting from a Windows environment to a Linux environment, see if the program dos2unix is available. This changes all the newline characters from Windows newlines to Linux newlines. If you have dos2unix, you can run it on your program as follows:

dos2unix filename.cgi

Your shebang looks old, try

Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/env perl
Not sure what the octal code is for this, but the folder containing your .cgi file should give read and execute permission to 'others', i.e.

chmod o+rx .

Your cgi file itself should have all permissions for user and no other permissions:

chmod 700 filename.cgi

(NOTE: This is all adapted from the course I took a few months ago. The professor taught how to use cgi on our school's servers, so I'm not sure how much of this is universal and how much of this was specific to my classmates and me.)
Nov 10 '08 #5

numberwhun
Expert Mod 2.5K+
P: 3,503

dos2unix filename.cgi
Actually, in the *nix world, the dos2unix command needs two file names, an input and an output. If you have read/write for the file in question, the input and output file names can be the same file name. So, the above would be:

Expand|Select|Wrap|Line Numbers
  1. dos2unix filename.cgi filename.cgi
  2.  
Otherwise, all it will do is output the cleaned up text to the screen for you to see.

Regards,

Jeff
Nov 10 '08 #6

Ganon11
Expert 2.5K+
P: 3,652
Actually, in the *nix world, the dos2unix command needs two file names, an input and an output. If you have read/write for the file in question, the input and output file names can be the same file name. So, the above would be:

Expand|Select|Wrap|Line Numbers
  1. dos2unix filename.cgi filename.cgi
  2.  
Otherwise, all it will do is output the cleaned up text to the screen for you to see.

Regards,

Jeff
It doesn't appear you are right...at least, on my machine. Typing:

dos2unix test.pl

does not print anything out to my screen, but in fact executes just fine.

Here's an excerpt from my console:

Expand|Select|Wrap|Line Numbers
  1. patty Programming in Perl $ man dos2unix
  2. Reformatting page.  Please Wait... done
  3. When called without parameters, the utility reads from the  stan-
  4. dard  input,  transforming  CR/LF  pairs into an LF character and
  5. writing it to the standard  output.   If  there's  at  least  one
  6. filename  specified,  the  operands are processed in command line
  7. order, reading from the files specified and overwriting them with
  8. the converted version.
"If there's at least one filename specified, the operands are processed...reading from the files specified and overwriting them with the converted version."

Check your manpage to see if it differs.
Nov 10 '08 #7

numberwhun
Expert Mod 2.5K+
P: 3,503
Its funny. I checked my home system (where I am now) and its the same way you described, but on other systems its how I mentioned. I think the best advice is to read the documentation before using it to be sure which one you are using. :)

Thus, we are both right and I learned that there are different versions.

Regards,

Jeff
Nov 10 '08 #8

Ganon11
Expert 2.5K+
P: 3,652
Absurd! We can't both be right! I propose Mortal Kombat to decide who shall prevail.

Back to the real world, reading the manpage would be the preferred solution, I suppose.
Nov 10 '08 #9

KevinADC
Expert 2.5K+
P: 4,059
Absurd! We can't both be right! I propose Mortal Kombat to decide who shall prevail.
Duels are against forum guidelines.
Nov 10 '08 #10

eWish
Expert 100+
P: 971
Another suggestion for you to consider.

--Kevin
Nov 11 '08 #11

KevinADC
Expert 2.5K+
P: 4,059
Another suggestion for you to consider.

--Kevin
Thats a great article by Brian, the only thing he doesn't mention is incorrect line endings (I think).
Nov 11 '08 #12

Ganon11
Expert 2.5K+
P: 3,652
He briefly touches on it, but doesn't really explain well how to deal with porting across different OSs.
Nov 11 '08 #13

Icecrack
Expert 100+
P: 174
Has this user Fixed his problem?

if not another thing he should be looking at is the apache/IIS logs.
Nov 19 '08 #14

Post your reply

Sign in to post your reply or Sign up for a free account.