?
Solved

500 error on scripts

Posted on 2003-02-26
16
Medium Priority
?
215 Views
Last Modified: 2010-03-04
I have Apache 1.3.26 on RHL 7.3.  Right now I am trying to get Apache to work with CGI.  Currently I have:

#ScriptAlias /cgi-bin/ "/home/httpd/domain/cgi-bin"

AddHandler cgi-script .cgi .pl

<Directory "/home/httpd/domain/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow, deny
Allow from All
</Directory>

If I go to www.domain.com/cgi-bin/script.pl I get a 500 error.

I originally tried to go to just www.domain.com/cgi-bin but I was getting a Forbidden Error.  To get to be able to go to www.domain.com/cgi-bin I had to REM out ScriptAlias.  I have chmod 755 my cgi-bin folder and all of its files within it.  To get the scripts to run, will I need ScriptAlias not to be REMed out?

If I take out the AddHandler cgi-script .cgi .pl command it works (which I don’t know why it wouldn’t, it would treat it like a regular file.) But as expected, when I went to try the script, I got a 405 Method Not Allowed error.

Any suggestions?

Thanks
0
Comment
Question by:ThinkGeekness
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 5
16 Comments
 
LVL 8

Expert Comment

by:heskyttberg
ID: 8029842
Hi!

The following should work.

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

The thing to check is that:
/home has 755 permission.
/hom/httpd has 755 permission.
/home/httpd/domain has 755 permission.
/home/httpd/domain/cgi-bin has 755 permission.

If you comment out ScriptAlias you need to add the following instead.

Alias /cgi-bin/ "/home/httpd/domain/cgi-bin"
Inconjunction with the add handler.

Hope this helps
Regards
/Hans - Erik Skyttberg
0
 

Author Comment

by:ThinkGeekness
ID: 8029931
Thanks for the reply.  I couldnt get the ScriptAlias to work, I was getting a Forbidden error, so I tried the Alias.  That is giving me the same error, the 500 error when I click on a script, .cgi or .pl.  The error message in the log is:

[error] [client 192.168.0.2] Premature end of script headers: /home/httpd/domain/cgi-bin/cgi-lib.pl

Hopefully that will help.

Thanks
0
 
LVL 8

Expert Comment

by:heskyttberg
ID: 8030071
Hi!

Well know it's working as it should.

This means you have done something wrong in you cgi script.

Try theese out:
::::::::::::::
test.cgi
::::::::::::::
#!/bin/bash
###############################################################################
# Created by Hans - Erik Skyttberg, Okt 2001
###############################################################################

  echo 'Content-type: text/html'
  echo ''
  echo '<HTML>'
  echo '<HEAD>'
  echo '<meta http-equiv=\"Content-Language\" content=\"sv\">'
  echo '<meta name=\"GENERATOR\" content=\"VIM\">'
  echo '<meta name=\"ProgId\" content=\"VIM.Editor.Document\">'
  echo '<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">'
  echo '<TITLE> TEST </TITLE>'
  echo '</HEAD>'
  echo '<BODY>'
  echo '<P>&nbsp;<FONT SIZE=\"5\"><B> TEST CGI SCRIPT !?! </B></FONT></P>'
  echo '</BODY>'
  echo '</HTML>'
::::::::::::::
test.pl
::::::::::::::
#!/usr/bin/perl
###############################################################################
# Created by Hans - Erik Skyttberg, Okt 2001
###############################################################################

  print "Content-type: text/html\n\n";
  print "<HTML>\n";
  print "<HEAD>\n";
  print "<meta http-equiv=\"Content-Language\" content=\"sv\">\n";
  print "<meta name=\"GENERATOR\" content=\"VIM\">\n";
  print "<meta name=\"ProgId\" content=\"VIM.Editor.Document\">\n";
  print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">\n";
  print "<TITLE> TEST </TITLE>\n";
  print "</HEAD>\n";
  print "<BODY>\n";
  print "<P>&nbsp;<FONT SIZE=\"5\"><B> TEST CGI SCRIPT !?! </B></FONT></P>\n";
  print "</BODY>\n";
  print "</HTML>\n";
exit(0);

Remove the three lines with :::::::.

Create that test.cgi and test.pl

If thoose work than you know your webserver is working.

Regards
/Hans - Erik Skyttberg
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:ThinkGeekness
ID: 8030181
Thanks! It turns out that it was the scripts, yours worked!  I have one more question, when I go to http://www.domain.com/cgi-bin/test.pl it adds a %20 after it showing http://192.168.0.4/cgi-bin/test.pl%20.  Is that normal?

Thanks!
0
 

Author Comment

by:ThinkGeekness
ID: 8030212
oops, dont worry about the http://192.168.0.4 part, I have to get to my domain that way and it looks like I didnt edit that out.
0
 

Author Comment

by:ThinkGeekness
ID: 8030316
Also, I am trying to edit my script, what is it that made so that your script will work?  Do you want me to post or email you my script?

Thanks
0
 

Author Comment

by:ThinkGeekness
ID: 8030358
Oh, one last thing (I bet you are getting tired of hearing this :) How would I actually call the script to action?  I said that it works because I could actually view the script for once with having the AddHandler. I tried just having a regular forum and having it submit, but I got a 404 error when I submitted.
0
 
LVL 8

Expert Comment

by:heskyttberg
ID: 8030399
Hi!

If you look in the top of my scripts they have:
Content-type: text/html\n\n

This is probably what you are missing since your error was premature end of script headers.

It could aslo be the firs line in your scripts are wrong.

You will get 500 error if you at first line in script has this:
#!/usr/bin/local/perl

When your perl interpreter is located in /usr/bin/perl.

The %20 behind is not normal behaviour, I don't know about that, maybe you got a 'perl.pl ', if you did cut and paste, so when you cut and paste the same into your browser it will exchange ' ' for %20 since ASCII code 20 equals ' '.

So if you go to your unix box and do more "test.pl" and this dosen't work.

Try more 2test.pl "
If this work you have your answer.

As far as your scripts, if you post it I can help you check what is wrong.

Regards
/Hans - Erik Skyttberg
0
 
LVL 8

Accepted Solution

by:
heskyttberg earned 225 total points
ID: 8030405
Hi!

If you look in the top of my scripts they have:
Content-type: text/html\n\n

This is probably what you are missing since your error was premature end of script headers.

It could aslo be the firs line in your scripts are wrong.

You will get 500 error if you at first line in script has this:
#!/usr/bin/local/perl

When your perl interpreter is located in /usr/bin/perl.

The %20 behind is not normal behaviour, I don't know about that, maybe you got a 'perl.pl ', if you did cut and paste, so when you cut and paste the same into your browser it will exchange ' ' for %20 since ASCII code 20 equals ' '.

So if you go to your unix box and do more "test.pl" and this dosen't work.

Try more 2test.pl "
If this work you have your answer.

As far as your scripts, if you post it I can help you check what is wrong.

Regards
/Hans - Erik Skyttberg
0
 

Author Comment

by:ThinkGeekness
ID: 8030426
Thanks, I am still wondering about how to actually use the script in a forum, since I tried to just do a simple forum with only a 'submit' button but I got a 404 error (I am wanting to make sure Apache can actually use CGI)

Here is the start and end of my script (thanks for debugging):

#!/usr/bin/perl

$recipient = "name\@domain.com";

$mailprog = '/usr/bin/sendmail';
$okay = 0;
$time = localtime(time);

print "Content-type: text/html\n\n";
&error;
&thanks;
&mailit;
&footer;

sub error {
  if ($FORM{'name'} eq "") {
    $errortext = "Please go back and enter your name."; }
  elsif ($FORM{'email'} eq "") {
    $errortext = "Please go back and enter your email address."; }
  elsif ($FORM{'phone'} eq "") {
    $errortext = "Please go back and enter your phone number." }
  elsif ($FORM{'message'} eq "") {
    $errortext = "Please go back and complete your message." }
  else { $okay = 1; }

  if ($okay == 0) { &errordisplay; exit; }
}

sub errordisplay {

#----middle of document---

sub mailit {

  open (SM, "|/usr/lib/sendmail $recipient") || die "Can't open $mailprog!\
n";
  print SM "To: $recipient\n";
  print SM "From: $FORM{'name'} <$FORM{'email'}>\n";
  print SM "Subject: Contact Us\n";
  print SM "\n";

print SM <<"END-MAIL";

Message sent at $time from $ENV{'REMOTE_HOST'}, $ENV{'HTTP_USER_AGENT'}:

Name: $FORM{'name'}\n
Phone: $FORM{'phone'}\n
Email: $FORM{'email'}\n
$FORM{'message'}


END-MAIL

  if ($? != 0 ) {               # we got a non 0 return code from sendmail.
   die "sendmail failed with return code $?";
  }
}

Thanks
0
 

Author Comment

by:ThinkGeekness
ID: 8030447
Okay... this is weird... The script works if I have a space at the end, but it doesnt, if I dont have a space.  I just changed the test.pl script to make is so that it wont have a space, and I got the forbidden error.  I just put a space at the end of the script that I posted above and it worked.  What would cause this?
0
 
LVL 8

Expert Comment

by:heskyttberg
ID: 8030606
Hi!

I have no idea, other than are you using IE ?

If you are consider switching to Netscape while developing.

Since if you make a page wrong and IE happens to cache it.
IE will still give you the cached page 9 times out of 10 even if you have corrected the problem, this has almost driven me insane when debugging sometimes.

I almost always forget about this IE 'feature' too.
Even if you tell IE to check the page every time, it dosen't then you still get cached page but only 6 times out of 10.

Only one might get IE to relize there is a new page is to close all open IE windows which you don't always wanna do and restart it.

Think Opera might be a good choice too, but I try to use Netscape since if I tell it to always check the page it eill.

I'll look at your script tomorrow.

Regards
/Hans - Erik Skyttberg
0
 

Author Comment

by:ThinkGeekness
ID: 8030674
Thanks for the suggestion, I just opened it up with Mozilla and I got the same error message if I dont have a space, 500 Internal Server Error.  I dont think that you need to look at the script, I think that it will work if I can get it working without having to have the space at the end.

Thanks
0
 

Author Comment

by:ThinkGeekness
ID: 8036287
I just pointed the forum to my script, and I got a Forbidden error.  I dont know what to do.... Could somebody send me their httpd.conf file who has Apache 1.3.26 or suggest a site where I can see the whole file?

Thanks
0
 

Author Comment

by:ThinkGeekness
ID: 8036364
Oh, one more thing... I would like the script sent to me to have CGI being able to work.  My email is Thinkgeekness@hotmail.com
0
 

Author Comment

by:ThinkGeekness
ID: 8036385
Edit: Not script as I said in my last post, I ment the httpd.conf file.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question