|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Problem with Apache & Perl on Windows
I just wrote a really long, detailed explanation of what is wrong but it was lost by the dang browser. I'll make this much more to the point.
Perl 5.6.1 and Apache 1.3.20 installed on Windows Me. I'm using the exact same http.conf file at work, minus the email address for ServerName, and everything works fine there. I've tried unsuccessfully to upload the file for y'all to browse. Sorry. When I run PRINTENV.PL with this in the code: Code:
print "Content-type: text/plain\n\n"; Internet Explorer 5.5 tries to download the file instead of executing it. The problem is solved somewhat if I change the above line to this: Code:
print "Content-type: text/html\n\n"; The line breaks are lost and the formatting is not what is intended. No bid deal ... ... except I cannot run this script at all at home Code:
#!/Perl/bin/perl.exe
print <<END_OF_HTML;
Content-type: text/html
<html>
<head>
<title>About this Server</title>
</head>
<body>
<h1>About this Server</h1>
<hr>
<pre>
Server Name: $ENV{SERVER_NAME}
Listening on Port: $ENV{SERVER_PORT}
Server Software: $ENV{SERVER_SOFTWARE}
Server Protocol: $ENV{SERVER_PROTOCOL}
CGI Version: $ENV{GATEWAY_INTERFACE}
</pre>
<hr>
</body>
</html>
END_OF_HTML
and it runs easy as pie at work. I get a server error 500 and this in the error.log file Code:
Premature end of script headers: c:/program files/apache group/apache/cgi-bin/server_info.cgi Can't find string terminator "END_OF_HTML" anywhere before EOF at c:\PROGRA~1\APACHE~1\APACHE\CGI-BIN\SERVER~1.CGI line 3. This post is a follow up to an earlier thread. I've made, or at least tried, all suggested edits to the httpd.conf file. Obviously, the shebang line is correct and Perl is running correctly. Help is most appreciated. |
|
#2
|
||||
|
||||
|
The best solution is to learn how to code with CGI.pm. It'll take care of all your header problems for you, and avoid "here docs", which is what your using with your "END_OF_HTML" construct.
Have you made sure there are no blank spaces before your ending END_OF_HTML? You can't have any whitespace the way you're using it. Here's your script rewritten in CGI.pm: Code:
#!/usr/bin/perl
use CGI;
my $q=CGI->new();
print
$q->header(),
$q->start_html(-title=>'About this Server'),
$q->h1('About this Server'),
$q->hr();
my $output;
foreach (%ENV){
$output.= "$_<br>";
}
print
$output,
$q->end_html();
Little more succinct, but if you're going to do more complex HTML you should look into a template engine like HTML::Template. Embedding HTML in code makes for a horrible mess to maintain later. |
|
#3
|
|||
|
|||
|
hmm ...
Hero-
Thanks for the bit about CGI.pm. I'm still learning Perl so my skills are limited, but I do recognize the advantages of mastering CGI.pm. I posted that script mainly because it is an example used in CGI Programming by O'Reilly which I did get to work on my computer at work (Perl 5.6.1 & Apache 1.3.20). I've also been wondering about printing HTML more easily so I will investigate HTML::Template. As for the whitespace, there is none and I got your script to work just fine. I suspect there is still something wrong with my setup of Apache, but I have no idea what. Why would the above script work on one computer and not another? |
|
#4
|
||||
|
||||
|
I really doubt the problem is with apache. As you said, perl is executing your script, and your error log is complaining about not finding the END_OF_HTML token. This definitively says to me the problem is in your script. If apache and perl working together were screwed up, you probably wouldn't get anything at all.
One other thing is win32 and unix use different line endings- on unix they are just "\n" and on win32 they are "\r\n". Have you opened and saved your script on your windows box, as a way of fixing your line endings? Open it in notepad and take a look at it. Does your script look strange? Is there a line ending after the END_OF_HTML token? I think there should be, if I remember right. |
|
#5
|
|||
|
|||
|
Well, why does this script, the example in the O'Reilly book, work on my other computer (and probably for most others since it is an example used in a book)?
I've written the script in Windows and I'm running Apache and Perl on Windows so I don't see how the different line endings in Unix would come into play. |
|
#6
|
||||
|
||||
|
If perl weren't set up to work correctly with apache you would get NOTHING. No error logs, no scripts working correctly AT ALL. You'd get either the script as plain text in your browser or a permissions error from the browser saying you can't access the script. This is obviously not the case here, you can run other scripts, presumably from the same location, fine.
There is no magical thing going on here, I'm sure there's just something wrong either with your script or possibly even with how perl is configured, though I suspect it's probably the former and not the latter. |
|
#7
|
|||
|
|||
|
cool
Hero-
Cool, I'll snoop around Perl and see if I can find something. |
|
#8
|
|||
|
|||
|
Writhe,
I tried the exact script you posted on me Win2K machine and it worked just fine. That leads me to believe that your installation of Apache is incorrectly configured. Post the lines where Perl is configured and we'll see if something is wrong with those.
__________________
- dsb - ![]() Perl Guy |
|
#9
|
|||
|
|||
|
dsb-
Yeah, and it works here at my office (Win 95), too. Not sure if I've got all the Perl configuration lines. Let me know if I'm missing some. Code:
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache/cgi-bin/"
#
# "C:/Program Files/Apache Group/Apache/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "C:/Program Files/Apache Group/Apache/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
and, further down ... Code:
#
# AddHandler allows you to map certain file extensions to "handlers",
# actions unrelated to filetype. These can be either built into the server
# or added with the Action command (see below)
#
# If you want to use server side includes, or CGI outside
# ScriptAliased directories, uncomment the following lines.
#
# To use CGI scripts:
#
#AddHandler cgi-script .cgi
#
# To use server-parsed HTML files
#
#AddType text/html .shtml
#AddHandler server-parsed .shtml
Keep in mind, I've tried uncommenting AddHandler and adding .pl but it still doesn't work. |
|
#10
|
|||
|
|||
|
Try having both in and uncommented:
Code:
AddHandler cgi-script .cgi AddHandler cgi-script .pl ...and make sure that your script is name with one of those extensions. |
|
#11
|
|||
|
|||
|
tried it
dsb-
Tried that already. I'll give it one more shot tonight when I get home. |
|
#12
|
|||
|
|||
|
nada
dsb-
Well, I didn't have time to mess around with this last night but I got to it tonight. I added the the handlers as you suggested and it still either tries to download PRINTENV.PL (with text/plain in code) and returns "Can't find string terminator" in the error log file when I run the SERVER_INFO.CGI (O'Reilly example) script. Any other ideas? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Problem with Apache & Perl on Windows |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|