# Creating a ruby "CGI" script

**URL:** <https://www.ruby-forum.com/t/creating-a-ruby-cgi-script/91542>\
**Category:** Ruby\
**Created:** [April 10, 2007, 9:05am UTC](https://www.ruby-forum.com/t/creating-a-ruby-cgi-script/91542 "2007-04-10T09:05:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![barjunk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@barjunk](https://www.ruby-forum.com/u/barjunk)\
**Post date:** [April 10, 2007, 9:05am UTC](https://www.ruby-forum.com/t/creating-a-ruby-cgi-script/91542/1 "2007-04-10T09:05:40Z")

</div>

I have been working with one of the Mentors from  
[rubymentor.rubyforge.org](http://rubymentor.rubyforge.org). Through our e-mail conversation and some  
experimenting, I learned several things. I am posting them here  
because I think it is helpful to all who might come after me and to  
show my appreciation for the help that has been given.

There were several parts to making a ‘CGI’ script using ruby:

- Configuring the apache server(that’s what I was using): Some  
important points are to have the Options +ExecCGI options for your  
particular site and for ScriptAlias to be pointing at the directory  
that contains the intended ruby script. Looking at the apache log  
files started me in the right direction for these things.

- Writing the script: There is a reasonable example in the online  
book ( [Programming Ruby: The Pragmatic Programmer's Guide](http://www.ruby-doc.org/docs/ProgrammingRuby/html/web.html) ).  
However, what it didn’t mention is that you can test things by  
executing the program on the command line and providing your  
environment variables to the script followed by a control-D. I found  
this after googling a little.

- Setting permissions: This is obvious for most people…but it  
should be mentioned. The permissions on your script need to be set so  
that your webserver will be able to read and execute them ( anyone  
want to share best practices here?)

It would be great if others with way more experience could clear up  
any mistatements I might have made because of my lack of experience.  
Best practices examples are most welcome.

Thanks.

Mike B.

---

<div class="post-metadata">

**Author:** ![barjunk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@barjunk](https://www.ruby-forum.com/u/barjunk)\
**Post date:** [April 10, 2007, 9:16am UTC](https://www.ruby-forum.com/t/creating-a-ruby-cgi-script/91542/2 "2007-04-10T09:16:43Z")

</div>

On 4/10/07, barjunk [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> particular site and for ScriptAlias to be pointing at the directory
> 
> - Setting permissions: This is obvious for most people…but it  
> Mike B.

Hello Mike,

glad you benefited from RubyMentor.

Would you two agree to post your conversation logs to the wiki?  
Currently there’s only mine and Samantha’s, and I’d like there to be  
more examples.

That and it being a great resource, too.

Aur
