#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/.
Note
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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.