Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

apache CGI - Internal Server Error

Status
Not open for further replies.

snookmz

Programmer
Apr 17, 2001
46
AU
G'day all

Iv been setting up Apache 1.3.* on redhat linux, and im encountering a bizarre problem.. Whenever i try to execute a script i get a 500 error.. Now, in the error logs its telling me that there is no such file or directory, even though its pointing to a file that is there.. Its also spitting out the "premature end of scripts headers" error.. Just for a test iv given permissions to everyone to execute the script..

Has anyone got any further tests i can run on it, or can you point me in another direction??

p.s. Iv also disabled suEXEC

thanks in advance, and i hope my query makes sense! /-------------------------------------
| I always have been, and
| always will be, a newbie :)
\-------------------------------------
 
To run cgi on your server check your httpd.conf and make sure you have these 3 directives defined:
1) ScriptAlias (this says pretend the cgi-bin is under the DocumentRoot and treat all files as cgi scripts)
2) Options ExecCGI (some servers work without this but what the heck)
3) AddHandler (If you have cgi scripts outside the ScriptAlias directory then then determine type by extention)

This is how they are used:

ScriptAlias /cgi-bin/ "/var/
<Directory &quot;/var/ AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

AddHandler .cgi .pl

The &quot;Premature end of header error&quot; is caused from something funky in the header. A couple things that could cause this are html file where a cgi script was expected (double check your paths). Another common cause is a corrupt file. This can be caused by zipping a file under Windows and unzipping them under linux where CR LF are incorrectly replaced with LF. Sometimes this shows up a strange chars at the end of each line when viewed with a plain text editor.
 
Hi,

Another thing to check....

Make sure the path on the first line of the scripts is correct. For example a perl script on redhat should have :

#!/usr/bin/perl

You'll have problems if the path is different or if you don't even have perl installed (rpm -q perl) .

Regards



 
brilliant!!!!

Thank you both for your help.. Now, can you tell a newbie why iv got to specify ScriptAlias, AND tell it the directory down further?? Am i missing something, why do i have to specify it twice??

The thing i didn't have was AddHandler, but i don't think it should have mattered as all the scripts were in the &quot;/home/webmaster/pub/cgi-bin/&quot; directory anyway.. :/

Thanks for your help though, the both of you

ScriptAlias /cgi-bin/ &quot;/home/webmaster/pub/cgi-bin/&quot;

#
# &quot;/var/ should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory &quot;/home/webmaster/pub/cgi-bin&quot;>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
/-------------------------------------
| I always have been, and
| always will be, a newbie :)
\-------------------------------------
 
I'll try to explain it better if I can. The ScriptAlias directive does two things. It aliases the actual path to appear to be off the DocumentRoot. For example, the url in the web browser sees your script in when in reality the cgi-bin is somewhere else. The Script part tells apache to treat ALL files in that directory and its sub-directories as scripts. The container tells apache who and what is allowed in that directory. ExecCGI is not a directive. It is an option. It tells apache to allow execution of cgi scripts in that directory. The AddHandler directive tells apache how to handle scripts with .cgi and/or .pl extensions. Without this it would not know how to handle a .cgi file if it is outside the ScriptAlias directory. I hope I got it right. :eek:)
 
Thanks Again RythemAce

With your fine advice i have moved a step further with my apache configuration, and im getting a new error (yaay error change is good).. im getting a &quot;Method Not Allowed&quot;, and its telling me that a POST method is not allowed to my cgi-bin directory..

Now, the 'webmaster' owns the file, in the group 'apache'.. Is that right in your opinion??

If you have time to answer this i'll be very appreciative, but if not, thanks for all your help so far, i'm really gratefull!!!

thanks again! :eek:) /-------------------------------------
| I always have been, and
| always will be, a newbie :)
\-------------------------------------
 
You can change the owner:group or just set permissions so the everybody can read and execute the scripts. To be able to post they will also need write permissions in those directories and files.
 
O RhythmAce

Fine master of all that is apache.. here is my apache cgi-bin configuration as it stands now

ScriptAlias /cgi-bin/ &quot;/home/webmaster/pub/cgi-bin/&quot;

#
# &quot;/var/ should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory &quot;/home/webmaster/pub/cgi-bin&quot;>
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>

AddHandler cgi-script .pl

I have also given read & write access to apache 'user', and also tested it by giving several other users complete read/write access.. And alas, im still getting &quot;500, Internal Server Error&quot;..

I then look in my log files only to find:

[Tue Jan 29 11:31:31 2002] [error] (2)No such file or directory: exec of /home/webmaster/pub/cgi-bin/activation/webmaster.pl failed

[Tue Jan 29 11:31:31 2002] [error] [client 192.91.185.218] Premature end of script headers: /home/webmaster/pub/cgi-bin/activation/webmaster.pl

So its telling me it can't find the webmaster.pl script in the cgi-bin directory.. but its THERE, and iv tested that its finding it by giving it a dud file thats definatly not there, and i get the &quot;File not Found&quot; error.. so its SEEING it, but not recognising it or something :/

what is a boy like me to do with such anarchy??? Or maybe its just so sane that it just blew my mind :(

anyway, if you could shed any light on the matter i would be eternally in your debt (even more-so)..

thanks again, :) /-------------------------------------
| I always have been, and
| always will be, a newbie :)
\-------------------------------------
 
If the dir paths are correct, it should work based on the section of httpd.conf you supplied. The first error is saying that the file pointed to is not a script so it just says it can't execute the file. The second error says that the file it DID find didn't have a correct header. If you check the shebang as infincham suggested and it is pointing to perl, then make sure there is no blank line after it. That has been known to cause this problem. also make sure permissions are set to executable by at least owner and group (chmod 775). You might also check that webmaster belongs to group apache. However, I'd think this would cause a permission error in your logs. Do you get any errors when you restart apache? These could be helpful. If it's a warning httpd may still start and if you're not looking you wouldn't know. You could also type httpd - t to check for syntax. If none of these work, we may have to start looking at perl, modules and mime.types. I'll keep my fingers crossed. :eek:)
 
You end the path in your script alias with a slash, but not in your directory. That could cause a problem. End 'em both with a slash.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top