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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting CGI to work

Status
Not open for further replies.

linuxpyro

Technical User
Feb 11, 2003
38
US
I am relatively new to Apache. I have it installed with Red Hat Linux version 8, and am trying to run CGI scripts. However, I have been having trouble. I rote a simple one, checked it over, and put it into the cgi-bin directory. But all I get are internal server errors. I figure that this is either a permission problem, or a directive one. (It's probably something small that I've overlooked.) I tried setting the permissions of the script to 777, and also uncommenting the AddHandler directive.
Thanks.
 
What are the server error messages? Newposter
"Good judgment comes from experience. Experience comes from bad judgment."
 
By the way, did you install PERL (part of the RedHat package) when you installed linux? Newposter
"Good judgment comes from experience. Experience comes from bad judgment."
 
Perl itself seems to be running fine; I was able to execute a test script from the command line. As for the error messages, they read:

Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers: perl_test.cgi
If you think this is a server error, please contact the webmaster
Error 500
 
To get cgi scripts to work you need the following:

1) a directory to hold your scripts (usually cgi-bin).
2) directory permissions set so 'others' can read and execute.
3) the directive 'ScriptAlias' points to this directory.
4) If you have a directory container defined for it, you need to 'allow' or 'deny' access to the directory.

The premature end of script header means it couldn't read the header either because it was missing, or for some reason wasn't able to read the script at all.
 
I have the cgi-bin directory scriptaliased, I chmoded it to 777, and the directory container reads as follows:
<Directory &quot;/var/ AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
 
I also tried changing the Options None directive to Options ExecCGI, but still no luck.
 
It seems like you have everything setup correctly. Does your script know where to find perl? The first line in your script should look like this:

#!/usr/bin/perl

The AddHandler and ExecCGI directives are just used if you will be running scripts outside of the cgi-bin.
 
I just ran into this problem last night. I was trying to implement an older linux script that worked on someone else's server. Here's the solution: the first two lines of your script file must be:

#!/usr/bin/perl
print &quot;Content-type: text/html\n&quot;;

Check to be sure the first line really is the path to your PERL executable; for my version of linux, that had changed.

The second line was in my script file, but further down. Moving it up to where it is fixed my problem. Newposter
&quot;Good judgment comes from experience. Experience comes from bad judgment.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top