# Basic CGI question

**URL:** <https://rubytalk.org/t/basic-cgi-question/2751>\
**Category:** ruby-talk\
**Created:** [8 November 2002 17:02 UTC](https://rubytalk.org/t/basic-cgi-question/2751 "2002-11-08T17:02:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Probert2](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@Mark\_Probert2](https://rubytalk.org/u/Mark_Probert2)\
**Post date:** [8 November 2002 17:02 UTC](https://rubytalk.org/t/basic-cgi-question/2751/1 "2002-11-08T17:02:40Z")

</div>

Hi, Rubyists.

I’m just starting to play with cgi and forms. I have a simple script  
which runs okay, except that the page changes to 500: Internal Server  
Error, with the error message “Premature end of script headers” on  
the script.

Search, this seems to be a permissioning problem. Permissions are 755.  
Ideas?

Ruby 1.7.3 (mswin), Apache 2.0.43, Win2k.

> cat lform.rb

require ‘cgi’  
require ‘log4r’

# add some basic logging

> **···**
>
> # 
> 
> logger = Log4r::Logger.new(‘lform’)  
> Log4r::FileOutputter.new(‘logfile’,  
> :filename=\>‘logs/lform.log’,  
> :trunc=\>true,  
> :level=\>Log4r::DEBUG)  
> logger.add(‘logfile’)
> 
> # cgi
> 
> # 
> 
> cgi = CGI.new  
> cgi.params.each { |key, val|  
> logger.debug “key=#{key} val=#{val}”  
> }
> 
> -mark.

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard1](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Ara.T.Howard1](https://rubytalk.org/u/Ara.T.Howard1)\
**Post date:** [8 November 2002 17:53 UTC](https://rubytalk.org/t/basic-cgi-question/2751/2 "2002-11-08T17:53:33Z")

</div>

if the cgi runs from the command line, but does not from the browser, chances  
are that user nobody (or www or whatever) does not have permission to _write_  
to the specified directory. two things which generally help me alot with  
cgis are

- get sudo su nobody permission - run all your scripts from the command line  
as user nobody (or www, or whatever apache runs as)

- when all else fails, make everything 777 (chmod -R 777) and run again, if  
that works the problem IS a permissions one, track it down and gradually  
shut permissions down untill it stops working - you found the problem

-a

> **···**
>
> On Sat, 9 Nov 2002, Mark Probert wrote:
> 
> > I’m just starting to play with cgi and forms. I have a simple script  
> > which runs okay, except that the page changes to 500: Internal Server  
> > Error, with the error message “Premature end of script headers” on  
> > the script.
> > 
> > Search, this seems to be a permissioning problem. Permissions are 755.  
> > Ideas?
> 
> –
> 
> ====================================
> 
> > Ara Howard  
> > NOAA Forecast Systems Laboratory  
> > Information and Technology Services  
> > Data Systems Group  
> > R/FST 325 Broadway  
> > Boulder, CO 80305-3328  
> > Email: [ahoward@fsl.noaa.gov](mailto:ahoward@fsl.noaa.gov)  
> > Phone: 303-497-7238  
> > Fax: 303-497-7259  
> > ====================================

---

<div class="post-metadata">

**Author:** ![Wesley\_Moxam](https://avatars.discourse-cdn.com/v4/letter/w/bb73d2/32.png) [@Wesley\_Moxam](https://rubytalk.org/u/Wesley_Moxam)\
**Post date:** [8 November 2002 19:11 UTC](https://rubytalk.org/t/basic-cgi-question/2751/3 "2002-11-08T19:11:54Z")

</div>

Are you printing an http header?

eg:  
puts “Content-type: text/html\n\n”

or, using the cgi object

cgi.out {  
“this is some html text”  
}

– Wes

> **···**
>
> ----- Original Message -----  
> From: “Mark Probert” [probertm@nortelnetworks.com](mailto:probertm@nortelnetworks.com)  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Friday, November 08, 2002 12:02 PM  
> Subject: Basic CGI question
> 
> > Hi, Rubyists.
> > 
> > I’m just starting to play with cgi and forms. I have a simple script  
> > which runs okay, except that the page changes to 500: Internal Server  
> > Error, with the error message “Premature end of script headers” on  
> > the script.
> > 
> > Search, this seems to be a permissioning problem. Permissions are 755.  
> > Ideas?

---

<div class="post-metadata">

**Author:** ![Mark\_Probert2](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@Mark\_Probert2](https://rubytalk.org/u/Mark_Probert2)\
**Post date:** [8 November 2002 20:10 UTC](https://rubytalk.org/t/basic-cgi-question/2751/4 "2002-11-08T20:10:11Z")

</div>

> > Search, this seems to be a permissioning problem. Permissions are 755.  
> > Ideas?

(I tried Ara’s idea of 777 and it doesn’t help… )

> Are you printing an http header?
> 
> eg:  
> puts “Content-type: text/html\n\n”

No, I was just reading the cgi.params.  
Do I need to write something as well?

-mark.

> **···**
>
> At 04:11 AM 11/9/2002 +0900, Weswrote:

---

<div class="post-metadata">

**Author:** ![Wesley\_Moxam](https://avatars.discourse-cdn.com/v4/letter/w/bb73d2/32.png) [@Wesley\_Moxam](https://rubytalk.org/u/Wesley_Moxam)\
**Post date:** [8 November 2002 20:24 UTC](https://rubytalk.org/t/basic-cgi-question/2751/5 "2002-11-08T20:24:24Z")

</div>

> > > Search, this seems to be a permissioning problem. Permissions are

1. 

> > > Ideas?
> 
> (I tried Ara’s idea of 777 and it doesn’t help… )
> 
> > Are you printing an http header?
> > 
> > eg:  
> > puts “Content-type: text/html\n\n”
> 
> No, I was just reading the cgi.params.  
> Do I need to write something as well?

Yes, I believe that you do. I don’t think that you can post a form to a cgi  
without returning _something_ to the client, and anything that you do send  
_must_ start with the Content-type header.

– Wes

> **···**
>
> ----- Original Message -----  
> From: “Mark Probert” [probertm@nortelnetworks.com](mailto:probertm@nortelnetworks.com)  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Friday, November 08, 2002 3:10 PM  
> Subject: Re: Basic CGI question
> 
> > At 04:11 AM 11/9/2002 +0900, Weswrote:

---

<div class="post-metadata">

**Author:** ![Mark\_Probert2](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@Mark\_Probert2](https://rubytalk.org/u/Mark_Probert2)\
**Post date:** [8 November 2002 20:52 UTC](https://rubytalk.org/t/basic-cgi-question/2751/6 "2002-11-08T20:52:58Z")

</div>

Hi, Wes.

> > No, I was just reading the cgi.params.  
> > Do I need to write something as well?
> 
> Yes, I believe that you do. I don’t think that you can post a form to a cgi  
> without returning _something_ to the client, and anything that you do send  
> _must_ start with the Content-type header.

That worked. I included

cgi.out {  
“this is some html text”  
}

And everything worked.

Maybe something for the CGI for Beginners FAQ.

Thanks for your help.

-mark.

> **···**
>
> At 05:24 AM 11/9/2002 +0900, you wrote:
