#41 A Simple CGI Script (simple_cgi.rb)

This script is fairly quick and dirty, but it shows the basics of how to use Ruby for CGI and introduces Ruby’s aptly named cgi library. You’ll need to put this script in your system’s cgi-bin directory. It’s /usr/lib/cgi-bin/ on my system, although your system’s location may be different. You can then browse to http://localhost/cgi-bin/simple_cgi.rb, because your webserver will provide access to the contents of your cgi-bin directory via http://localhost/cgi-bin/.


You’ll also need to give simple_cgi.rb 755 permissions, meaning that its owner can do anything with it and everyone else can read and execute it, but not write (change) it. For more information, see man chmod.

Before we even get started with ...

Get Ruby by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.