Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 24th, 2001, 08:52 PM
writhe writhe is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Houston
Posts: 9 writhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old July 24th, 2001, 09:17 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
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.

Reply With Quote
  #3  
Old July 24th, 2001, 09:51 PM
writhe writhe is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Houston
Posts: 9 writhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #4  
Old July 24th, 2001, 11:09 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
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.

Reply With Quote
  #5  
Old July 24th, 2001, 11:46 PM
writhe writhe is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Houston
Posts: 9 writhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old July 25th, 2001, 07:02 AM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
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.

Reply With Quote
  #7  
Old July 25th, 2001, 09:16 AM
writhe writhe is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Houston
Posts: 9 writhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
cool

Hero-

Cool, I'll snoop around Perl and see if I can find something.

Reply With Quote
  #8  
Old July 25th, 2001, 12:29 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
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

Reply With Quote
  #9  
Old July 25th, 2001, 12:58 PM
writhe writhe is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Houston
Posts: 9 writhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #10  
Old July 25th, 2001, 01:07 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
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.

Reply With Quote
  #11  
Old July 25th, 2001, 01:18 PM
writhe writhe is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Houston
Posts: 9 writhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
tried it

dsb-

Tried that already. I'll give it one more shot tonight when I get home.

Reply With Quote
  #12  
Old July 26th, 2001, 11:24 PM
writhe writhe is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Houston
Posts: 9 writhe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Problem with Apache & Perl on Windows


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |