rhtml and apache trouble

M

Mitul Ti

I am trying to run embedded ruby inside rhtml.

$cat test.rhtml

<% print "Content-type: text/html\n\n" %>



<html>
<body>
Testing <% foo = "Ruby"; print "#{foo}!" %>
</body>
</html>




It works fine from the command line:

$eruby test.rhtml


Content-type: text/html


<html>
<body>
Testing Ruby!
</body>
</html>



But inside my apache setup it doesn't work.

Accessing "http://localhost/cgi-bin/test.rhtml" gives following error:

"Internal Server Error

The server encountered an internal error or misconfiguration and was
unable to complete your request.

Please contact the server administrator, (e-mail address removed) and inform them
of the time the error occurred, and anything you might have done that
may have caused the error.

More information about this error may be available in the server error
log."

Error log says:

[Wed Jan 26 13:21:53 2011] [error] [client ::1] (8)Exec format error:
exec of 'Dir/cgi-bin/test.rhtml' failed
[Wed Jan 26 13:21:53 2011] [error] [client ::1] Premature end of script
headers: test.rhtml


I have copied "eruby" executable to "Dir/cgi-bin/" directory and
configured apache (2.2) as follows:

AddType application/x-httpd-eruby .rhtml
Action application/x-httpd-eruby Dir/cgi-bin/eruby

Any ideas? Thanks!
 
J

Justin Collins

I am trying to run embedded ruby inside rhtml.

$cat test.rhtml

<% print "Content-type: text/html\n\n" %>



<html>
<body>
Testing<% foo = "Ruby"; print "#{foo}!" %>
</body>
</html>




It works fine from the command line:

$eruby test.rhtml


Content-type: text/html


<html>
<body>
Testing Ruby!
</body>
</html>



But inside my apache setup it doesn't work.

Accessing "http://localhost/cgi-bin/test.rhtml" gives following error:

"Internal Server Error

The server encountered an internal error or misconfiguration and was
unable to complete your request.

Please contact the server administrator, (e-mail address removed) and inform them
of the time the error occurred, and anything you might have done that
may have caused the error.

More information about this error may be available in the server error
log."

Error log says:

[Wed Jan 26 13:21:53 2011] [error] [client ::1] (8)Exec format error:
exec of 'Dir/cgi-bin/test.rhtml' failed
[Wed Jan 26 13:21:53 2011] [error] [client ::1] Premature end of script
headers: test.rhtml


I have copied "eruby" executable to "Dir/cgi-bin/" directory and
configured apache (2.2) as follows:

AddType application/x-httpd-eruby .rhtml
Action application/x-httpd-eruby Dir/cgi-bin/eruby

Any ideas? Thanks!

Your .rhtml files shouldn't be in cgi-bin/, they should be in
public_html/ or similar. Looks like Apache's trying to execute the
rhtml file, which isn't an executable.

-Justin
 
M

Mitul Ti

Justin Collins wrote in post #977732:
Your .rhtml files shouldn't be in cgi-bin/, they should be in
public_html/ or similar. Looks like Apache's trying to execute the
.rhtml file, which isn't an executable.

-Justin


Thanks Justin for your comments!

I tried keeping .rhtml file in htdocs directory (DocumentRoot directory)
and I double checked the permission:

-rwxr-xr-x test.rhtml*

But I am still getting the same error. Any ideas? Thanks!
 
J

Justin Collins

Justin Collins wrote in post #977732:


Thanks Justin for your comments!

I tried keeping .rhtml file in htdocs directory (DocumentRoot directory)
and I double checked the permission:

-rwxr-xr-x test.rhtml*

But I am still getting the same error. Any ideas? Thanks!
Are you using http://localhost/test.rhtml as the URL?
 
B

Brian Candler

Mitul Ti wrote in post #977720:
I am trying to run embedded ruby inside rhtml.

$cat test.rhtml

<% print "Content-type: text/html\n\n" %>

One problem is that you must not output a blank line before the HTTP
headers. That will give the Apache error you saw, at least it does with
CGI scripts. (Having said that, I'm not 100% sure that rhtml files
should generate HTTP headers in the first place)

A second problem is that I don't think you should use 'print' inside
rhtml. Use <%= ... %> instead.

$cat test.rhtml
Content-Type: text/html

<html>
<body>
Testing <% foo = "Ruby" %> <%= "#{foo}!" %>
</body>
AddType application/x-httpd-eruby .rhtml
Action application/x-httpd-eruby Dir/cgi-bin/eruby

Have you installed a copy of eruby inside your cgi-bin directory in that
location? Is it executable?

To be honest, I think you'll find almost nobody uses ruby this way any
more, because it gives you the worst of all worlds: the inefficiency of
cgi-bin (forking a new ruby interpreter for every request) with the
PHP-like muddle of mixing your application logic inside your HTML
templates.

You should probably look at writing an application using a simple
framework like Sinatra, which is just a layer on top of Rack. For
development you can run it as a standalone webserver on its own port.
For production you can either run it inside Apache using Phusion
Passenger, or you can run a pool of mongrel/thin/unicorn/rainbows!
webservers and proxy to them.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top