views:

89

answers:

3

I recently discovered that CGI scripts can be written in pretty much any language that can print to stdout. I've written a small guile cgi script that works on my local apache install, but not on my shared host:

#!/usr/local/bin/guile -s 
!#
(display "Content-Type: text/html")
(newline)
(newline)
(display "hi")
(newline)

This is the output, when I run the script from a shell on my host over ssh:

$ ./scheme.cgi
Content-Type: text/html

hi

So, obviously my host has guile installed. However, when I try to access this file in a browser, I get a "500 Internal Server Error". When looking at my error logs, I see that I am getting the dreaded "premature end of script headers" error:

[server.com] [Tue Aug 17 00:54:19 2010] [error] [client xx.xx.xx.xxx] (2)No such file or directory:
exec of '/home/www/vhosts/jcw.geekisp.com/cgi-bin/scheme.cgi' failed

[server.com] [Tue Aug 17 00:54:19 2010] [error] [client xx.xx.xx.xxx] Premature end 
of script headers: scheme.cgi

Because I am on a shared host, using mod_lisp or guile's fastcgi implementation are out of the question. That being said, what could be the issue here? Similar cgi scripts I've written in python, perl, ruby, and sh work on the server with no errors. I see that guile 1.8.7 is installed on the host, but my local machine is on the newest version.

I understand that this is an incredibly niche question, any help would be appreciated!

+3  A: 

I believe that error means your web server process doesn't have access to the /usr/local/bin/guile interpreter. Check the permissions on that file, make sure it is accessible if the server runs in a chroot or under mandatory access control, etc. And double-check the permissions on your script while you're at it.

Karl Bielefeldt
I've changed the first line to "#!/usr/bin/env guile", and am getting the same errors. The guile binary has the same permissions as the python and ruby binaries it is sitting next to, except for o+w (and its group is bin, rather than wheel). I don't have permissions to chroot. The script's permissions are 755.
jcw
A: 

It turns out that, the /usr/local/bin directory that exists when I'm ssh'ed on the server is different from the /usr/local/bin when the script is served and accessed through a browser. I found out what interpreters were available through this CGI script:

#!/bin/sh
echo "Content type: text/html\r\n\r\n"
echo "ls /usr/local/bin"

When I ran this script through a browser, I found that mzscheme was listed, but not guile. So, problem solved, I'm using mzscheme.

Thanks, Karl.

jcw
+1  A: 

You might also be able to compile your own copy of guile or whatnot and store it in your ~/bin/ directory and have scripts point there.

erjiang
Excellent idea, thanks!
jcw