Apache2, CGI, Ruby & Hello-World

N

Nathan Farrar

According to ProgrammingRuby :
You can use Ruby to write CGI scripts quite easily. To have a Ruby
script generate HTML output, all you need is

Code:
#!/usr/bin/env ruby print "HTTP/1.0 200 OK\r\n" print "Content-type:
text/html\r\n\r\n" print "<html><body>Hello World!</body></html>\r\n"

I have a fresh install of ubuntu, almost no experience with apache, cgi,
or ruby, but a lot of patience.

I haven't modified my apache2 config, I haven't installed any extra
apache-ruby modules.

If you go to http://atraeyu.org/ you'll notice a ruby.htm file.
Obviously this won't execute. I'm wondering what I need to do to make it
execute.

Do I need to install to install an apache module? Can I simply change
the extension and set it to executable?

I imagine there are a few simple concepts I really don't understand that
I need to.
I will really appreciate any help. Thanks.
 
M

Michael Greenly

Nathan said:
According to ProgrammingRuby :
You can use Ruby to write CGI scripts quite easily. To have a Ruby
script generate HTML output, all you need is

Code:
#!/usr/bin/env ruby print "HTTP/1.0 200 OK\r\n" print "Content-type:
text/html\r\n\r\n" print "<html><body>Hello World!</body></html>\r\n"

I have a fresh install of ubuntu, almost no experience with apache, cgi,
or ruby, but a lot of patience.

I haven't modified my apache2 config, I haven't installed any extra
apache-ruby modules.

If you go to http://atraeyu.org/ you'll notice a ruby.htm file.
Obviously this won't execute. I'm wondering what I need to do to make it
execute.

Do I need to install to install an apache module? Can I simply change
the extension and set it to executable?

I imagine there are a few simple concepts I really don't understand that
I need to.
I will really appreciate any help. Thanks.


You should rename the file to something *.rb (hello.rb) for example and
make it's executable to apache. Set it's owner to www-data, the user
account apache runs under with the command "chown www-data:www-data
hello.rb". Then set it's permissions so it can be run "chmod 700
hello.rb".

Now you need to configure apache. Edit
"/etc/apache2/sites-available/default". In the <Directory /var/www>
section add the following line...

AddHandler cgi-script .rb

In the options line make sure it includes +ExecCGI so it should look
something like this....

Options +FollowSymlinks +ExecCGI

Have apache reload the config....

sudo /etc/init.d/apache2 reload
 

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,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top