Ruby as CGI with Apache on Linux

Z

Zach Dennis

I feel bad for asking this question, but I am going to pull my hair out with
this. I recently got Ruby to run as a cgi under Apache2/Win2k combination.
Works great. I am now trying to do the same thing on Apache2/Redhat9 combo,
but to no avail. I keep getting the Server Error 500, premature end of
script headers.

Here is my Apache config:
------------------------------
<VirtualHost *>
ServerAdmin root@localhost
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Files ~ "^\.htm">
Order allow,deny
Deny from all
</Files>
<Directory "/var/www/cgi-bin">
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
AddType application/x-httpd-ruby .rb
Action application/x-httpd-ruby /usr/local/bin/ruby
</VirtualHost>

Here is my Script that I am trying to run( test.rb ):
-----------------------------------------------------
#!/usr/local/bin/ruby
print "Content-type: text/html\r\n"
print "<html><body>Hello</body></html>"


I was having this problem on my windows box at first but then I changed the
first line to read:
#! ruby
and it has worked ever since. However I have changed the first line on my
test.rb file on the Linux box to the following variations:
#! ruby
#!/usr/local/bin/ruby
#!/bin/ruby
#!/bin/env ruby
#! /bin/env ruby
and to not avail does it work. All files are owned by root. Any ideas?
Thanks in advance,

Zach
 
A

Ara.T.Howard

I feel bad for asking this question, but I am going to pull my hair out with
this. I recently got Ruby to run as a cgi under Apache2/Win2k combination.
Works great. I am now trying to do the same thing on Apache2/Redhat9 combo,
but to no avail. I keep getting the Server Error 500, premature end of
script headers.

Here is my Apache config:
------------------------------
<VirtualHost *>
ServerAdmin root@localhost
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Files ~ "^\.htm">
Order allow,deny
Deny from all
</Files>
<Directory "/var/www/cgi-bin">
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
AddType application/x-httpd-ruby .rb
Action application/x-httpd-ruby /usr/local/bin/ruby
</VirtualHost>

i'm sure about this virtual/app-handler type set up, but it seems like you may
need an ExecCGI in there somewhere...
Here is my Script that I am trying to run( test.rb ):

this does not work, you must have _two_ \r\n terminators

#!/usr/local/bin/ruby
print "Content-type: text/html\r\n\r\n"
print "<html><body>Hello</body></html>"

better still (since you never need remember this):

#!/usr/local/bin/ruby
require 'cgi'
CGI.new.out { said:
I was having this problem on my windows box at first but then I changed the
first line to read:
#! ruby
and it has worked ever since. However I have changed the first line on my
test.rb file on the Linux box to the following variations:
#! ruby
#!/usr/local/bin/ruby
#!/bin/ruby
#!/bin/env ruby
#! /bin/env ruby
and to not avail does it work. All files are owned by root. Any ideas?
^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^

all files should not owned by root. they should be owned, readable, and
executable by, the web user. this is probably user nobody, httpd, or apache
depending on your distro/config.

do

ps -elf | egrep 'httpd'

to find out


HTH.

-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top