Thanks, rj2 but in this case I'm writing directly on the server. So it's not an FTP issue either.
Main Topics
Browse All TopicsI'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/northro
Premature end of script headers: /home/httpd/vhosts/northro
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>\
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.
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.
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.
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.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
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.
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...
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
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/northr
but no luck
Where exactly would be the directive to allow CGI scripting?
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
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.
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/northr
<Directory "/home/httpd/vhosts/northr
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
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>\
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
Business Accounts
Answer for Membership
by: rj2Posted on 2002-12-19 at 07:55:12ID: 7608160
Try to upload it in ASCII mode, not binary mode.