Apache and Ruby

  • Thread starter Phillip Neiswanger
  • Start date
P

Phillip Neiswanger

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 =3D 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 incantati=
on =

do I need to get it working? I'm running Opera/FireFox, Apache 2.2.3 an=
d =

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.
 
J

Justin Collins

Phillip said:
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.

Do you have mod_ruby installed?

-Justin
 
P

Phillip Neiswanger

un =
I =
am =
Do you have mod_ruby installed?

-Justin

Thanks for the reply Justin. I fixed my problems with the following lin=
es =

in httpd.conf

Options ExecCGI
AddHandler cgi-script .rb

I also had to make sure the .rb files had the appropriate group ownershi=
p.
 
P

Père Noël

Phillip Neiswanger said:
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 ?
 
J

Justin Collins

Père Noël said:
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

Père Noël

Justin Collins said:
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...
 
J

Justin Collins

Père Noël said:
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...

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
</Directory>

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

-Justin
 
P

Père Noël

Justin Collins said:
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
</Directory>

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 ;-)

anyway that cures the prob, thanks a lot !
 
D

David Vallner

--------------enig69E0C79B3612A6E8D7DB8ABD
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Justin said:
My mistake...I'm not much of an expert on this. You will need to add a
directory directive like:
=20
<Directory /var/www/html/somedir/*>
Options +ExecCGI
</Directory>
=20
in the config file to have it work right. Sorry about that.
=20
-Justin
=20

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 Vallner


--------------enig69E0C79B3612A6E8D7DB8ABD
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFdzlFy6MhrS8astoRAibxAJ9gAxm9pFsKbLcQaGPyxj00iPEuYgCeOlqE
BZG5Mh46E1WkmKS8B2vfF9g=
=msnc
-----END PGP SIGNATURE-----

--------------enig69E0C79B3612A6E8D7DB8ABD--
 
P

Père Noël

David Vallner said:
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 ?
 
D

David Vallner

--------------enig5D3223F1D99B98C9F0B950A5
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

P=E8re No=EBl said:
t"
=20
content negociation is doable with Apache 1.3 (default installed versio= n
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.
=20
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 Vallner


--------------enig5D3223F1D99B98C9F0B950A5
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD4DBQFFd6+3y6MhrS8astoRAnaKAJiioPQ5v5nWzUNN2AQlNGjOl7sXAJ9E5Rom
yWwi57D2K+Dt7P74IwIwMg==
=qmZJ
-----END PGP SIGNATURE-----

--------------enig5D3223F1D99B98C9F0B950A5--
 

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,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top