It seems very funny to me that when I search something related ruby, all ruby on rails related results popped up. So nobody using raw ruby anymore?
However, I am new to ruby. This morning I was only trying to run a simple hello world ruby script in web server, firstly apache 2 and then tried the mongrel. But unfortunately I failed. I googled every way I can, but result only shows regarding ruby on rails. So really is there any way to run a ruby script in any web server, or I have to use ror even if I just want to do a hello world application?
You could try with ruby -run -e httpd . -p 8000 , which will start a WEBrick server on your current directory. Show activity on this post. Just type rails s or rails server into the terminal.
rb ("runner bee") allows you to run Ruby code in the browser. To get started, click the play button in the bottom of the editor.
The Ruby standard library comes with a default web server named WEBrick. As this library is installed on every machine that has Ruby, most frameworks such as Rails and Rack use WEBrick as a default development web server.
Sinatra is probably your best bet for getting a Ruby script running from a web server without Rails.
Take a look here: http://www.sinatrarb.com
From the Sinatra docs:
require 'sinatra'
get '/hi' do
"Hello World!"
end
Then, just run:
$ gem install sinatra
$ ruby -rubygems hi.rb
== Sinatra has taken the stage ...
>> Listening on 0.0.0.0:4567
Just go to http://0.0.0.0:4567 in your browser and you should find your "Hello World"
...
To add on to this, since you also ask about running in Apache or other web servers, you may want to check out these tutorials about deploying your new Sinatra-based application to Apache or Nginx:
Apache: http://www.pastbedti.me/2009/11/deploying-a-sinatra-app-with-apache-and-phusion-passenger-a-k-a-mod_rack/ and http://www.giantflyingsaucer.com/blog/?p=1716
Nginx: http://tommy.chheng.com/2009/06/09/deploying-a-sinatra-app-on-nginx-passenger-with-capistrano-and-git/
Note both tutorials cover running Sinatra via Passenger (http://www.modrails.com/ -- don't be put off by the "modrails" name :) ), which I have had good luck with in deploying apps under Apache and Nginx.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With