Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Premature end of script headers error

by huklberry (Novice)
on Jul 01, 2006 at 23:25 UTC ( #558812=perlquestion: print w/replies, xml ) Need Help??
huklberry has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to setup the apache web server on a linux fedora platform. Everything seems to be working with the exception of executing a perl script when invoked from a webpage. Every time I try to execute my perl script from my webpage I get an "500 Internal Server Error" and the following error logs:

(13)Permission denied: exec of '/cgi-bin/' failed Premature end of script headers:

I've triple checked the permissions of the cgi-bin directory and the perl script and they look fine...

drwxr-xr-x 2 root root 4096 Jul 1 17:38 cgi-bin [root@localhost cgi-bin]# ll -rwxr-xr-x 1 root root 159 Jul 1 17:38

I've verified the location of my cgi-bin directory is correct. When I remove I get a "404 Not Found" error instead of the server error. I also verified the script runs fine from the command line. My script is very basic and intended only to verify I can execute perl scripts. Code is below...

#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; print "Content-type: text/html\n\n"; print "testing testing\n"; exit;

Any thoughts on what I could be doing wrong would be greatly appreciated.

Replies are listed 'Best First'.
Re: Premature end of script headers error
by imp (Priest) on Jul 02, 2006 at 01:20 UTC
    Your permissions look ok, and if it was a problem with ExecCGI not being allowed or a bad interpreter you would see a different error message.

    I searched a bit and found this info: manpage for httpd_selinux

    It sounds like you might need to do this: chcon -R -t httpd_sys_script_exec_t <path to the cgi directory>


      The chcon command you recommended fixed my problem. Thanks for all the help everyone.
Re: Premature end of script headers error
by Zaxo (Archbishop) on Jul 02, 2006 at 01:11 UTC

    Your web server configuration may not yet know what to do with cgi files.

    Are "Options +ExecCGI", "ScriptAlias'", " AddHandler cgi-script cgi pl", and maybe "UserDir" set? The apache httpd manual has details of how to choose sane settings for those.

    (Added) Come to think of it, the "Premature end of script headers" message indicates that httpd is trying to treat your script correctly, so ignore the above. By chance are you uploading the script from a winders box? If so you may have a bogus \r tacked onto the perl path in the splatline. Insert a space and a comment or something to check that.

    After Compline,

      I tested this on my server and having ExecCGI disabled resulted in the following: Options ExecCGI is off in this directory

      If the AddHandler lines were missing then it would just render as whatever DefaultType is set to.

Re: Premature end of script headers error
by ioannis (Monsignor) on Jul 02, 2006 at 02:48 UTC
    According to your error messages, I suspect the exec bit is not turned on, do: chmod +x (or whatever is required so the apache User has permissions to run it.)

    I would also uncomment CGI::Carp until things work, just to ensure that is compilable.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://558812]
Approved by graff
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-03-23 23:43 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (297 votes). Check out past polls.