Suggestions: perl/cgi on apache:linux...problems running script from browser, works fine from command line

My setup is Apache, Linux, Perl.

I'm running RH9 with a new standard install of all required tools (perl, mysql, php, etc.)

the issue im having is trying to get the scripts to run from the browser...all i get is internal server error...i check the logs and most of the time all i see is premature end of headers. if i issue the command "perl anyscript.cgi" from the command line it works/generates desired html code. ive double checked permissions and syntax and am a stand still at this point.

does this sound like a httpd.conf issue?

fyi: the scripts do work, ive run them successfully on my sun box.

any suggestions?

Who is Participating?
I'd be inclined to get a bit more error reporting from the script.

#!/usr/bin/perl -w

use strict;

print "Content-type: text/html\n\n";

and see if any more errors appear.
Note, your script may generate loads of warnings when you run with strict enabled, if it's too
must to cope with, try without the strict, and just see what the -w flag gives you.

It sounds to me like a script problem, rather than an issue with your httpd conf (though you never
know for sure until it works...)
premature end of headers- u get this error when there is information being passed to the browser before the headers are being passed

programs run on solaris successfully need not run successfully on linux
 print "Content-type: text/html\n\n";

On linux, make sure this is the first line in your perl scripts.
If shell script just translate print into echo.

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

nriddockAuthor Commented:
does the print command go before or after the #!/usr/bin/perl?
The print command goes after the #!... so, you use:


print "Content-type: text/html\n\n";  # Make sure you have to \n's here - very important!

### Rest of script here.
nriddockAuthor Commented:
tried's still erroring out...any other suggestions?

does this sound like an apache issue (httpd.conf) or more of a script/syntax issue?

just an my experience, there errors are normally caused quite early on in the execution
of a script, often by a require statement. It might be worthwhile just pasting the first few lines of the
script in question (say 20-30) - I might be able to spot something obvious straightaway.
nriddockAuthor Commented:
that did it...

#!/usr/bin/perl -w

the "-w" seemed to make all the difference. what exactly does the W do?

the use strict seemed to cause errors so i removed it. Thanks for all your help. Enjoy the extra points.

-w basically enables warnings, which makes troubleshooting perl problems *far* easier.
use strict makes perl 'paranoid' - things have to be 'right' for the script to execute without
generating errors ie:
$x = 10; # will give an error, since x has not been declared but...
my $x = 10; # will not give an error, since x has been declared

As the perl manpage says in the 'bugs' section - 'The -w switch is not mandatory' should
always use it when running perl.

Thanks for the extra points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.