Question

PERL CGI - Premature end of script headers:

Asked by: andersongrant24

I've tried all kinds of permissions combinations and simplified the program as much as possible.  I just can't seem to find what's keeping perl from running as a CGI.

I'm getting this error in the log at:
/home/httpd/vhosts/northrockbp.com/logs/error_log

Premature end of script headers: /home/httpd/vhosts/northrockbp.com/cgi-bin/hello.pl

Here's the script I'm using:
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";

print "<html><head>\n";
print "<title>Hello, world!</title></head>\n";
print "<body><h1>Hello, world!</h1></body></html>\n";

The permissions on the file are:
-rwxr-xr-x    1 northroc psacln        184 Dec 19 09:53 hello.pl

The permissions on the cgi-bin are:
drwxr-xr-x    2 northroc psacln       4096 Dec 18 16:36 cgi-bin

The perl location is:
# which perl
/usr/bin/perl

The output from the command line is:
# perl hello.pl
Content-type: text/html

<html><head>
<title>Hello, world!</title></head>
<body><h1>Hello, world!</h1></body></html>

From the browser I'm getting the standard:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request...Apache/1.3.22 Server at www.northrockbp.com Port 80

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2002-12-19 at 07:43:36ID20431601
Tags

perl

Topics

Perl Programming Language

,

Server Side Includes (SSI)

Participating Experts
7
Points
185
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CGI and httpd?
    I'm running RedHat6.0 out of the box, and I'm trying to get httpd to handle CGI scripts. But when I point Navigator to file:/home/httpd/html/anlgform.html, I get: "unable to find the file or directory named /cgi-bin/anlgform.cgi" It seems like I'm set up correctly:...
  2. Perl/cgi problem
    I'm having a problem with my new Linux Install. When i try to run a cgi or .pl file i get bad command - but when i type /usr/bin/perl file namke it works - i've got #!/usr/bin/perl at the top of my script - do i need to do something else ?? - I've granted the correct rights...
  3. Perl CGI
    Hi, I'm new in Perl/CGI world. I have a html page that contains a call to .cgi file. However, seems like it doesn't work. I did install a Sambar Web Server in my pc & load the cgi-lib.pl in my /cgi-bin directory. I have no ideas in solving this probs. test.html--->p...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: rj2Posted on 2002-12-19 at 07:55:12ID: 7608160

Try to upload it in ASCII mode, not binary mode.

 

by: andersongrant24Posted on 2002-12-19 at 07:57:50ID: 7608173

Thanks, rj2 but in this case I'm writing directly on the server.  So it's not an FTP issue either.

 

by: serg111Posted on 2002-12-19 at 09:18:52ID: 7608607

Second line of script should be empty:

not


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


but

#!/usr/bin/perl -w

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

 

by: seesikPosted on 2002-12-19 at 09:19:36ID: 7608611

works for me. try ./hello.pl just to see if you've got a shiesty linefeed on the hashbang line. vi should show hat m
's (^M) if so.

 

by: seesikPosted on 2002-12-19 at 09:22:05ID: 7608623

serg111, what the hell should the second line of your script be empty for? that's utter b.s.

 

by: andersongrant24Posted on 2002-12-19 at 09:24:08ID: 7608635

serg111 - no luck

seesik - what do you mean exactly.  I'm not that familiar with vi

 

by: seesikPosted on 2002-12-19 at 09:34:11ID: 7608673

you're using the simplest possible example, so we're not looking for a syntax error. i'm not sure what platform/editor you're using (some nix variant obviously), but there's a pretty common problem w/ symptoms similar to yours. different platforms use different end-of-line characters, special characters that most editors don't display. we're looking for an invisible trailing \r\n after your hashbang line. the easiest thing to do to ensure you don't have that problem would be to just delete and retype that "#!/usr/bin/perl -w" line again.

did ./hello.pl work?

tbc...

 

by: seesikPosted on 2002-12-19 at 09:35:46ID: 7608681

serg111, what the hell should the second line of your script be empty for? that's utter b.s.

 

by: PeeweePosted on 2002-12-19 at 10:25:37ID: 7608906

andersongrant24,

this can be only one of a few problems?

A:
syntax error  - No
lines endings - Possible
perl location - Possible
apache server error - Possible
upload problem - No

your sntax is fine and this basic script works fine on my windows box under apache server.  This does not mean it will work under linux due to line endings. To get rid of any line endings at the unix prompt type dos2unix filename and then chmod 777 filename.

retest and see what happens?

if still no good, check your path to perl ie your first line, are you sure this pointing to perl.  if still no luck check your apache logs and see what the error message is:

ie my logs are at:

tail -f /etc/httpd/logs/error_log  

and then run the script in the browser again check the error, report back with it.


one final question, you have configured cgi on your server haven't you, you can check by looking in the conf file, mime is at /etc/httpd/conf/httpd.conf  


let me know if you need more help.
regards Peewee




 

by: andersongrant24Posted on 2002-12-19 at 11:02:46ID: 7609078

Peewee

syntax error  - No
lines endings - Possible - it's not this, I created the file on Linux, I double checked it all, even ran dos2unix
perl location - Possible - the "which perl" and "whereis perl" both show it in the right place
apache server error - Possible - is possible
upload problem - No

We recently had somebody upgrade PHP and he may have made some changes to the config files.  I don't know.  What specifically should I be looking for in the httpd.conf file.  I found it at /etc/httpd/conf/httpd.conf

I searched for CGI in there and there was a ExecCGI that was not specified under Options.  I specified it and restarted apache but no luck.

the ScriptAlias says
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
and I tried putting
ScriptAlias /cgi-bin/ "/home/httpd/vhosts/northrockbp.com/cgi-bin/"
but no luck

Where exactly would be the directive to allow CGI scripting?

 

by: PeeweePosted on 2002-12-19 at 11:46:37ID: 7609301

andersongrant24,

eliminate all the other options before looking at the server.

but:

ScriptAlias allows cgi scripts to execute in ther specified directory only, ie outside this and cgi will not work.

and:

AddHandler cgi-script .cgi

would allow file scripts with .cgi extension to be forced as CGI statements..


regards Peewee

 

by: andersongrant24Posted on 2002-12-19 at 12:01:44ID: 7609407

I did the AddHandler thing like this
AddHandler cgi-script .cgi
AddHandler cgi-script .pl

and now the script runs if I run it out of ...com/hello.pl but it won't run out of ...com/cgi-bin/hello.pl

funny huh.  

That tells me that the script is structured fine and also that perl is working fine.  And the fact that I'm getting a 500 error and not a 404 error tells me that the script is being found.  But for some reason it just won't run CGI in the CGI bin.

 

by: andersongrant24Posted on 2002-12-19 at 12:08:55ID: 7609444

I tried this for the script alias.  Is this right?  I just changed the option to ExecCGI and changed the paths from the default server CGI-BIN

    # Specify CGI-BIN for NorthrockBP
    ScriptAlias /cgi-bin/ "/home/httpd/vhosts/northrockbp.com/cgi-bin/"

    <Directory "/home/httpd/vhosts/northrockbp.com/cgi-bin">
        AllowOverride None
        Options ExecCGI
        Order allow,deny
        Allow from all
    </Directory>

 

by: TintinPosted on 2002-12-19 at 13:12:41ID: 7609779

I'll make a fair bet that the problem is buffering.  "Premature end of script headers" means the script has not outputted the correct headers.

Try this:

#!/usr/bin/perl

$|=1;  # Turn buffering off.

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

print "<html><head>\n";
print "<title>Hello, world!</title></head>\n";
print "<body><h1>Hello, world!</h1></body></html>\n";

 

by: andersongrant24Posted on 2002-12-19 at 13:46:01ID: 7609980

I used an AddHandler and got all my CGI scripts working but they are not working in the CGI-BIN (everywhere but the CGI-BIN, go figure)

Thanks for the help PeeWee

 

by: PeeweePosted on 2002-12-20 at 02:05:49ID: 7612577

andersongrant24,

glad to be of help

regards Peewee

 

by: daggPosted on 2003-02-07 at 23:09:44ID: 7907802

I just ran into this exact problem and it turned out
my webserver provider is using "suexec" with Apache.
When that option of Apache is turned on, you have
to make sure of two main things:

1. Your CGI script is _not_ group or world writeable.

2. The directory that the CGI script is in is _not_
  group or world writeable.

After I ran:

  chmod go-w cgidir/myscript.pl

and

  chmod go-w cgi-dir/

my CGI script ran perfectly.

More info about "suexec" is here: http://www.apache.org/docs/suexec.html

 

by: ren_bPosted on 2004-02-15 at 17:22:51ID: 10368386

this is indeed an old paq. anyway i came across this problem and it had to do with my text encoding when i saved it. the settings on my text editor was set to save in unicode, and changing it back to the local encoding (mac roman if on mac), fixed it.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...