PDA

View Full Version : Trouble linking html to cgi


petersonryanace
01-28-2004, 06:34 PM
The answer is not chmod... i don't think.

I'm getting started with cgi and perl in order to do something with some forms in html. Non-interactive sites are boring! I've started at ground level doing some basic hello world stuff. I've found the tutorial here (http://www.troubleshooters.com/codecorn/littperl/perlhelo.htm) to be most helpful in stating my problem.

I can run a hello world perl script and a cgi script, i can dump the perl output to a html file that loads (although the content-type line appears in the browser still which is troubling), i can run cgi file using ./ notation or perl filename.cgi. But, when I try to start with an html page, something like this:

Content-type: text/html

<P><A HREF="hello.cgi">RUN hello.cgi</A>.</P>

Clicking the link only links me to a text version of the hello.cgi file, it doesn't execute the script. Sounded like it had to be a chmod problem so i did chmod 755 hello.cgi, reloaded the webpage and clicked the link. Same result. Where is the problem? Browser, perl, cgi, html, or something else. Admittedly, I am running on some odd SGI machines for the most part but the perl and cgi work fine on their own.

Any help getting me off the ground would be great.

Ace

YUPAPA
01-28-2004, 10:11 PM
Your HTTP server doesn't know .cgi is a CGI script... you probably have to add the extension so that the HTTP knows .cgi is a cgi script and it executes it... if you are using apache, try add

AddHandler cgi-script .cgi

petersonryanace
01-28-2004, 11:24 PM
thanks...
but... no dice. I presume (after doing some reading) that I put this line (and this line only) in the .htaccess file that I create in the same directory (I presume it's not looking for this file buried in some other directory?). So this is the only line in the file:

AddHandler cgi-script .cgi

Do I need to chmod this file too? Can I check what server I'm on with some shell command? Is there any hope if I'm not on Apache? Thanks for your help so far.

Ace

YUPAPA
01-28-2004, 11:35 PM
I do not know about any other HTTP server other than apache... if you are running apache, yes you can add the handler to the .htaccess file instead of modifying the main configuration file (httpd.conf) The .htaccess file should be placed to the same directory where the script is located.

example:
/home/username/myscript.cgi
/home/username/.htaccess


And yes you have to change permission for the script. IT should be 0755 (-rwxr-xr-x)

Paul-Ecchi
01-29-2004, 02:20 AM
Are you certain your host allows you to execute scripts, and if so are you certain you have put it in the correct place. All the hosts I use insist that all scripts are in the cgi-bin. If your script is in a place where your host has not allowed scripts, it will simply see it as a text file and you will get the result you say. For the link you mentioned to work, the script would have to be in the same place as your html page, and I have never known a host that allows this. Check your host's FAQ, and if you do not find the answer there ask them directly where the scripts should be.

petersonryanace
01-29-2004, 04:10 PM
Thanks everyone. I guess I thought that we had server stuff installed locally and that I could check my code locally. That appears not to be the case. I will try to install a server (good tutorial, I think, available here (http://hotwired.lycos.com/webmonkey/00/44/index4a.html). I also don't think my server supports taking users cgi scripts. But I've sent a word into them. Thanks for your help.

Ace