[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie tearing hair out

page77.office

1/4/2006 11:25:00 AM

I am trying to get to grips with ruby as an alternative to PHP.

My plan is to convert a simple PHP application to ruby, as I definitely
like the language better from what I have seen.

I have downloaded instantrails and after adding the missing log
directories, it runs the sample appications, mycookbook and typo.

So now I have mysql and apache running - great - and it was an almost
one-click install.

So now I decide Rails is far too involved for me at my stage of
development and I do not really appreciate what it is doing, other than
providing framework for pages. I am sure it will be very good, but for
now I want to just use ruby as my scripting language for web pages on
an intranet.

I have chosen instantrails, because I wanted Apache and Mysql and
phpMyAdmin, for my current PHP application, I had used WAMP and it
worked seamlessly. I was looking to do the same with Ruby. I suppose
I want WAMR - Windows, Apache, Mysql and Ruby.

I am running Windows XP SP2, but if the project is successful, I will
be moving it to a virtual linux box, using Debian. I am very flaky
with the Linux as I did a bit of UNIX, years ago - but I try.

So to my problem. I have created a 'helloworld' web page and called it
'testcgi.rb'. I have put it in various directories, but whenever I try
to execute it as a web page on my localhost - it just prints out the
contents. I look at httpd.conf and tremble, although I am not sure
which is the right one. I have installed 'instantrails' under
c:\rubyrail

Contents of testcgi.rb

#!/usr/bin/ruby
# HTTP response headers, including double newline
print "Content-type: text/plain\n\n"
# Contents
print "Hello, world from Tim\n"

I suspect it may be something to do with mod_ruby, fastcgi, scgi, but
at the moment as my 'sample rails apps' work, why won't my simple
xxxx.rb execute ?

So how do I get an xxxxx.rb file to execute and where an earth do
rhtml files fit in to the mix.

I appreciate I am probably misunderstanding some fundamental concept,
but having been around computers for 40 years, I like to know how the
nitty gritty fits together.

I have accessed many web pages with howto's etc, but none seem to
answer my questions, so any help or pointers would be greatly
appreciated.

As an aside my testcgi.rb will execute as a ruby script on my virtual
linux with ruby testcgi.rb but not as ./testcgi.rb and my permissions
are 755 - any pointers ?

Thanks

Richard

9 Answers

dsymonds

1/4/2006 11:33:00 AM

0

page77.off...@googlemail.com wrote:

> So to my problem. I have created a 'helloworld' web page and called it
> 'testcgi.rb'. I have put it in various directories, but whenever I try
> to execute it as a web page on my localhost - it just prints out the
> contents. I look at httpd.conf and tremble, although I am not sure
> which is the right one. I have installed 'instantrails' under
> c:\rubyrail
>
> Contents of testcgi.rb

Chances are it just needs to be called "testcgi.cgi" (i.e. using the
..cgi extension). This would be an Apache setup aspect.

The code is fine, by the way, though standards-wise you'd be better
using "\r\n\r\n" to end the HTTP headers, not just "\n\n".


Dave.

dsymonds

1/4/2006 11:41:00 AM

0

dsymo...@gmail.com wrote:
> The code is fine, by the way, though standards-wise you'd be better
> using "\r\n\r\n" to end the HTTP headers, not just "\n\n".

To head off any other comments: My reference is RFC2616
(http://www.ietf.org/rfc/r...), section 4.1 (CRLF=="\r\n" before
body).


Dave.

page77.office

1/4/2006 11:42:00 AM

0


dsymonds@gmail.com wrote:
> page77.off...@googlemail.com wrote:
>
> > So to my problem. I have created a 'helloworld' web page and called it
> > 'testcgi.rb'. I have put it in various directories, but whenever I try
> > to execute it as a web page on my localhost - it just prints out the
> > contents. I look at httpd.conf and tremble, although I am not sure
> > which is the right one. I have installed 'instantrails' under
> > c:\rubyrail
> >
> > Contents of testcgi.rb
>
> Chances are it just needs to be called "testcgi.cgi" (i.e. using the
> .cgi extension). This would be an Apache setup aspect.
>
> The code is fine, by the way, though standards-wise you'd be better
> using "\r\n\r\n" to end the HTTP headers, not just "\n\n".
>
>
> Dave.

Thanks for the tip. I have had it called testcgi.cgi and I just get it
printed out, not executed.

Richard

Curt Hibbs

1/4/2006 12:05:00 PM

0

You'll need to do some searching for how to sertup CGI to execute Ruby
scripts (you probably beed to install mod_ruby). This does not come
with Instant Rails, which is designed specifically to run Rails web
apps via SCGI.

Curt

On 1/4/06, page77.office@googlemail.com <page77.office@googlemail.com> wrote:
>
> dsymonds@gmail.com wrote:
> > page77.off...@googlemail.com wrote:
> >
> > > So to my problem. I have created a 'helloworld' web page and called it
> > > 'testcgi.rb'. I have put it in various directories, but whenever I try
> > > to execute it as a web page on my localhost - it just prints out the
> > > contents. I look at httpd.conf and tremble, although I am not sure
> > > which is the right one. I have installed 'instantrails' under
> > > c:\rubyrail
> > >
> > > Contents of testcgi.rb
> >
> > Chances are it just needs to be called "testcgi.cgi" (i.e. using the
> > .cgi extension). This would be an Apache setup aspect.
> >
> > The code is fine, by the way, though standards-wise you'd be better
> > using "\r\n\r\n" to end the HTTP headers, not just "\n\n".
> >
> >
> > Dave.
>
> Thanks for the tip. I have had it called testcgi.cgi and I just get it
> printed out, not executed.
>
> Richard
>
>
>


Robert Klemme

1/4/2006 12:18:00 PM

0

page77.office@googlemail.com wrote:
> dsymonds@gmail.com wrote:
>> page77.off...@googlemail.com wrote:
>>
>>> So to my problem. I have created a 'helloworld' web page and
>>> called it 'testcgi.rb'. I have put it in various directories, but
>>> whenever I try to execute it as a web page on my localhost - it
>>> just prints out the contents. I look at httpd.conf and tremble,
>>> although I am not sure which is the right one. I have installed
>>> 'instantrails' under c:\rubyrail
>>>
>>> Contents of testcgi.rb
>>
>> Chances are it just needs to be called "testcgi.cgi" (i.e. using the
>> .cgi extension). This would be an Apache setup aspect.
>>
>> The code is fine, by the way, though standards-wise you'd be better
>> using "\r\n\r\n" to end the HTTP headers, not just "\n\n".
>>
>>
>> Dave.
>
> Thanks for the tip. I have had it called testcgi.cgi and I just get
> it printed out, not executed.

Once when I dealt with CGI scripts (a while ago) you had to create a
directory called "cgi-bin" in the root of the web application and place
your scripts there (with executable permissions). That was all that was
necessary to make them executable as CGI scripts.

Kind regards

robert

dsymonds

1/4/2006 12:30:00 PM

0

page77.office@googlemail.com wrote:
> Thanks for the tip. I have had it called testcgi.cgi and I just get it
> printed out, not executed.

Then I'll be a bit more explicit, this time for Apache:

(1) Turn on the CGI handler. You'll need a line like
AddHandler cgi-script .cgi
(this would also allow you to use the .rb extension)

(2) In whatever directory the script is in, you'll need the ExecCGI
option enabled. Either that, or use the ScriptAlias option of
mod_alias.

You do *not* need mod_ruby; it is optional, though it might come in
handy. You'll also need FastCGI setup for Ruby on Rails, though I could
be wrong on this point since I've never actually used Rails myself.


Dave.

Walter Prins

1/4/2006 12:35:00 PM

0

I think you need to configure apache to know that .rb extension files
are to be treated as CGI scripts to be run via the Rub interpreter (or
module.) (Note I have no experience with this setup, just limited
general experience with this sort of thing with Apache. ) Basically
you want to look into the Apache "ScriptAlias" directive and/or
"ExecCGI" option. See here:
http://www.serverwatch.com/tutorials/article.p...

Also you need to tell apache to add a handler for .rb files, for this
look into AddHandler directive. See e.g. here:
http://www.ricocheting.com/serve...

Hope this helps.

page77.office@googlemail.com wrote:

>I am trying to get to grips with ruby as an alternative to PHP.
>
>
>


james_b

1/4/2006 4:03:00 PM

0

Walter Prins wrote:
> I think you need to configure apache to know that .rb extension files
> are to be treated as CGI scripts to be run via the Rub interpreter (or
> module.) (Note I have no experience with this setup, just limited
> general experience with this sort of thing with Apache. ) Basically
> you want to look into the Apache "ScriptAlias" directive and/or
> "ExecCGI" option. See here:
> http://www.serverwatch.com/tutorials/article.p...
>
> Also you need to tell apache to add a handler for .rb files, for this
> look into AddHandler directive. See e.g. here:
> http://www.ricocheting.com/serve...
>


You'll need something like this in either a .htaccess file in the Web
app's document root directory, or in the httpd.conf file:


<Files ~ "\.(rb|rbx|cgi)$" >
SetHandler cgi-script
</Files>

Options +ExecCGI
DirectoryIndex index.cgi index.rb index.html


Also note that Apache on Windows can be configured in two different ways
to execute CGI scripts. In one approach, it looks at the #! line to
locate the interpreter, In the other, it ignores that line and just
uses whatever app is associated with the file extension of the scripts.


James



--

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - Ruby Code & Style: Writers wanted
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys
http://www.30seco... - Building Better Tools


page77.office

1/4/2006 9:41:00 PM

0

Many thanks to all who responded. It turned out that the problem was
that apache was configured to execute cgi scripts, but I did not have
the right first line.

For Windows/DOS the correct first line is

#! /ruby/bin/ruby.exe
or wherever your path to ruby is. The important part is to include
the .exe and use forward slashes /

I can now test my ruby scripts, by having them end in .cgi

I will investigate getting .rb to work based on your help.

Thanks to all - Richard

James Britt wrote:
> Walter Prins wrote:
> > I think you need to configure apache to know that .rb extension files
> > are to be treated as CGI scripts to be run via the Rub interpreter (or
> > module.) (Note I have no experience with this setup, just limited
> > general experience with this sort of thing with Apache. ) Basically
> > you want to look into the Apache "ScriptAlias" directive and/or
> > "ExecCGI" option. See here:
> > http://www.serverwatch.com/tutorials/article.p...
> >
> > Also you need to tell apache to add a handler for .rb files, for this
> > look into AddHandler directive. See e.g. here:
> > http://www.ricocheting.com/serve...
> >
>
>
> You'll need something like this in either a .htaccess file in the Web
> app's document root directory, or in the httpd.conf file:
>
>
> <Files ~ "\.(rb|rbx|cgi)$" >
> SetHandler cgi-script
> </Files>
>
> Options +ExecCGI
> DirectoryIndex index.cgi index.rb index.html
>
>
> Also note that Apache on Windows can be configured in two different ways
> to execute CGI scripts. In one approach, it looks at the #! line to
> locate the interpreter, In the other, it ignores that line and just
> uses whatever app is associated with the file extension of the scripts.
>
>
> James
>
>
>
> --
>
> http://www.ru... - Ruby Help & Documentation
> http://www.artima.c... - Ruby Code & Style: Writers wanted
> http://www.rub... - The Ruby Store for Ruby Stuff
> http://www.jame... - Playing with Better Toys
> http://www.30seco... - Building Better Tools