# Can't get basic CGI and Form submission working

**URL:** <https://www.ruby-forum.com/t/cant-get-basic-cgi-and-form-submission-working/104058>\
**Category:** Ruby\
**Created:** [May 13, 2007, 8:13pm UTC](https://www.ruby-forum.com/t/cant-get-basic-cgi-and-form-submission-working/104058 "2007-05-13T20:13:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [May 13, 2007, 8:13pm UTC](https://www.ruby-forum.com/t/cant-get-basic-cgi-and-form-submission-working/104058/1 "2007-05-13T20:13:27Z")

</div>

I’m not a programmer, but like to use Ruby for writing simple programs,  
mainly for helping with my day job (as a network engineer). My normal  
method of coding is to take an example out a book (“The Pragmatic  
Programmers Guide”, what else? :)) and tailor/expand it to to my needs.

I’ve just written a program which produces its results in HTML, for  
convenient viewing. I’m feeling a little more ambitious now and would  
like now to get a _small_ amount of interaction using simple forms.  
However, I’m not really getting past the first hurdle. I _thought_ that  
putting

 "STUFF" 

… would run the script indicated. Instead I get a ‘404’ “The  
requested URL \<path…\> was not found on this server.”

I also tried

 ... 

In fact, I tried this version first but it neither worked nor gave me  
any errors. I know the script in question itself works because I can  
run it from the command line (plus it is just creating a ‘Hello World!’  
file) - which is to say I chmod 755 the file and started it with the  
path to the Ruby bin.

I’m probably missing something really basic, and any advice would be  
gratefully received.

thanks in advance

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [May 13, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/cant-get-basic-cgi-and-form-submission-working/104058/2 "2007-05-13T20:20:06Z")

</div>

In message [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), Toby  
Rodwell writes:

> … would run the script indicated. Instead I get a ‘404’ “The  
> requested URL \<path…\> was not found on this server.”

The path you give must be the path within the web server’s view, not  
the filesystem path. So, “/home/bob/src/test.rb” won’t work, for  
instance. Typical would be to put the program in your server’s CGI  
directory, and specify “/cgi-bin/test.rb”.

-s

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [May 13, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/cant-get-basic-cgi-and-form-submission-working/104058/3 "2007-05-13T20:28:40Z")

</div>

unknown wrote:  
…

> The path you give must be the path within the web server’s view, not  
> the filesystem path. So, “/home/bob/src/test.rb” won’t work, for  
> instance. Typical would be to put the program in your server’s CGI  
> directory, and specify “/cgi-bin/test.rb”.
> 
> -s

Thanks ‘s’, that did the trick. I’ve now progressed one step to a new  
error message: "405 - POST Method not allowed for the URL "  
Anyone any ideas? I’m guessing either its another web server config  
issue or I’m not using ‘POST’ correctly …

Thanks again!

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [May 13, 2007, 8:49pm UTC](https://www.ruby-forum.com/t/cant-get-basic-cgi-and-form-submission-working/104058/4 "2007-05-13T20:49:55Z")

</div>

unknown wrote:  
…

> Sounds like the web server isn’t allowing POSTs to that directory.  
> Try changing the form to a GET and see whether it works; if it does,  
> that’s the issue.
> 
> This has fairly little to do with Ruby per se, and a lot to do with  
> whatever web server you’re running.
> 
> -s

Makes sense - I’ll investigate the web-server settings.

thanks  
Toby

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [May 13, 2007, 8:36pm UTC](https://www.ruby-forum.com/t/cant-get-basic-cgi-and-form-submission-working/104058/5 "2007-05-13T20:36:07Z")

</div>

In message [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), Toby  
Rodwell writes:

> Thanks ‘s’, that did the trick. I’ve now progressed one step to a new  
> error message: “405 - POST Method not allowed for the URL ”  
> Anyone any ideas? I’m guessing either its another web server config  
> issue or I’m not using ‘POST’ correctly …

Sounds like the web server isn’t allowing POSTs to that directory.  
Try changing the form to a GET and see whether it works; if it does,  
that’s the issue.

This has fairly little to do with Ruby per se, and a lot to do with  
whatever web server you’re running.

-s

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [May 14, 2007, 12:31am UTC](https://www.ruby-forum.com/t/cant-get-basic-cgi-and-form-submission-working/104058/6 "2007-05-14T00:31:36Z")

</div>

On May 14, 2007, at 3:35 AM, Peter S. wrote:

> that’s the issue.
> 
> This has fairly little to do with Ruby per se, and a lot to do with  
> whatever web server you’re running.
> 
> -s

True, it isn’t directly a Ruby issue, but it is an issue directly  
related to and important when dealing with many classes from the Ruby  
standard library, and no small number of gems.  
405 is a message like 404 Not Found. There’s a whole list of them.  
Server error messages for http.  
Make sure you’re using the right URI/URL.  
Also, your script may be trying to write inside the CGI-BIN  
directory. If it doesn’t have permissions for that, it won’t be able  
to do that (this is not unusual) it should be writing to some other  
location that is outside of executable space. A directory for read/  
write only (a data store) or a database. You have to learn a bit  
about where your web server puts things and what the host’s policies  
are. Some are more free about things than others, but all have  
individual quirks.  
Your account or your script may just not have permissions to execute  
the file. Or, the server admin doesn’t allow it or isn’t allowing  
you. You’ll have to ask them.
