09:17 PM

The Easiest Way To Run Ruby From Web Request

My Works, by Wei.

Of course that the most official way is use ROR(Ruby On Rails).

But it’s hard to build. And here is the easiest way to run ruby from web request.

(The whole passage is based on Debian 4.0 Linux)

First install ruby (for linux)

apt-get install ruby irb rdoc

And creat a new php file as:

1
2
3
4
5
6
<?php
$d = $_GET['d'];
system("ruby /rb/$d",$echo);
//You may change the direction that you want to put ruby programs.
echo $echo;
?>

And now you can run ruby with this php program.

Use the browser to open

yourdomain/yourphpfilename.php?d=yourbname.rb

And the ruby program will run and prints results.

And if you use Lighttpd webserv insert rewrite rule:

url.rewrite = (
"^/(.+.rb)$" => "/yourphpfilename.php?d=$1",
)

If you already have some rewrite rules insert another rewrite rule

"^/(.+.rb)$" => "/yourphpfilename.php?d=$1",

Other webserv will be kind of the same.

An’ now. You can run your ruby programs through visit:

yourdomain/yourrubyfilename.rb

Back Top

Responses to “The Easiest Way To Run Ruby From Web Request”

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Back Top

Note: Commenter is allowed to use '@User:' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC:'(exclude ') will automatically send your comment to ABC.