Apache and Ruby

Hi,

New to ruby and apache. Been trying to get a simple ruby script to run
via apache. The script is as follows:

#!/usr/bin/env ruby
require “cgi”
cgi = CGI.new(“html3”)
cgi.out(“text/plain”){
“Hello World”
}

I attempt to access it with my browser via an address like:
http://127.0.0.1/script.rb. Apache is clearly not running ruby since I
get the script back verbatim to the browser. Plain html, ie no ruby, is
working. So far, in my search for an answer I haven’t found anything to
alleviate my problems. Interestingly, I have eRuby working, ie I can
embed ruby code in my html, but not ruby. What special Apache
incantation
do I need to get it working? I’m running Opera/FireFox, Apache 2.2.3
and
Ruby 1.8.5 on FreeBSD 6.1 system. I am not interested in getting rails
working right now, just ruby.

Any help would be appreciated.

Phillip N. wrote:

}

Any help would be appreciated.

phil

Do you have mod_ruby installed?

-Justin

Phillip N. [email protected] wrote:

Thanks for the reply Justin. I fixed my problems with the following lines
in httpd.conf

Options ExecCGI
AddHandler cgi-script .rb

I also had to make sure the .rb files had the appropriate group ownership.

And u don’t need a special folder under your Apache/ROOT folder ?

On Tue, 05 Dec 2006 23:43:32 -0700, Justin C.
[email protected]
wrote:

"Hello World"

not interested in getting rails working right now, just ruby.

Any help would be appreciated.
– phil

Do you have mod_ruby installed?

-Justin

Thanks for the reply Justin. I fixed my problems with the following
lines
in httpd.conf

Options ExecCGI
AddHandler cgi-script .rb

I also had to make sure the .rb files had the appropriate group
ownership.

Père Noël wrote:

And u don’t need a special folder under your Apache/ROOT folder ?

No, you don’t have to set it up that way, although it’s an option.

-Justin

Père Noël wrote:

then i’ve tried that using an hello_world cgi this one :
folder…

u can see txt files at the same adresses extension added “.txt”

the added Apache directives are in the following file :

http://www.yvon-thoraval.com/httpd/mod_ruby_httpd.conf

also both files are executables…

My mistake…I’m not much of an expert on this. You will need to add a
directory directive like:

<Directory /var/www/html/somedir/*>
Options +ExecCGI

in the config file to have it work right. Sorry about that.

-Justin

Justin C. [email protected] wrote:

My mistake…I’m not much of an expert on this. You will need to add a
directory directive like:

<Directory /var/www/html/somedir/*>
Options +ExecCGI

in the config file to have it work right. Sorry about that.

why did u say it’s your mistake ?
because i’ve found these directives from mod_ruby archive :wink:

anyway that cures the prob, thanks a lot !

Justin C. [email protected] wrote:

And u don’t need a special folder under your Apache/ROOT folder ?

No, you don’t have to set it up that way, although it’s an option.

in the mean time i’ve installed mod_ruby.

then i’ve tried that using an hello_world cgi this one :

http://www.yvon-thoraval.com/ruby/hello_world

works as expected

and that one :

http://www.yvon-thoraval.com/httpd/hello_world.rbx

generates a 404 errror even if u’ve accessed to it by it’s parent
folder…

the content of both is the same except i write a shebang for the latest
(rbx) :

#! /usr/bin/env ruby

cgi=CGI.new
print cgi.header(“type” => “text/plain”)
print “Hello World !”

u can see txt files at the same adresses extension added “.txt”

the added Apache directives are in the following file :

http://www.yvon-thoraval.com/httpd/mod_ruby_httpd.conf

also both files are executables…

Justin C. wrote:

directory directive like:

<Directory /var/www/html/somedir/*>
Options +ExecCGI

in the config file to have it work right. Sorry about that.

-Justin

A point to note that was lost, it doesn’t have to be a special folder,
and it’s a bad idea to do so. Same for using the extension-based
handler.

Cf. http://www.w3.org/Provider/Style/URI, section on “What to leave out”

(Of course, you can safely ignore those guidelines when playing around,
just keep them in mind for “real” projects. On a related note, I also
find the slashified (in buzzwordspeak: RESTful) URLs sexy-looking as far
as URLs go ;P)

David V.

David V. [email protected] wrote:

A point to note that was lost, it doesn’t have to be a special folder,
and it’s a bad idea to do so. Same for using the extension-based handler.

Cf. http://www.w3.org/Provider/Style/URI, section on “What to leave out”

content negociation is doable with Apache 1.3 (default installed version
within MacOS X latest) ?

(Of course, you can safely ignore those guidelines when playing around,
just keep them in mind for “real” projects. On a related note, I also
find the slashified (in buzzwordspeak: RESTful) URLs sexy-looking as far
as URLs go ;P)

do you have an example, a link about that “slashified” URLs ?

Père Noël wrote:

David V. [email protected] wrote:

A point to note that was lost, it doesn’t have to be a special folder,
and it’s a bad idea to do so. Same for using the extension-based handler.

Cf. http://www.w3.org/Provider/Style/URI, section on “What to leave out”

content negociation is doable with Apache 1.3 (default installed version
within MacOS X latest) ?

There’s a mod_negotiation section in the manual for that version, so it
seems so. I’m hazy about the details since I rarely use CGI.

(Of course, you can safely ignore those guidelines when playing around,
just keep them in mind for “real” projects. On a related note, I also
find the slashified (in buzzwordspeak: RESTful) URLs sexy-looking as far
as URLs go ;P)

do you have an example, a link about that “slashified” URLs ?

For a mailing list (more or less) relevant one,
http://manuals.rubyonrails.com/read/chapter/65 describes a Rails feature
that lets you have those.

David V.

David V. [email protected] wrote:

There’s a mod_negotiation section in the manual for that version, so it
seems so. I’m hazy about the details since I rarely use CGI.

ok fine, i’ve verified in the mean time, content negociation does exist
with Apache 1.3

that lets you have those.
ok fine,thanks !