Koozali.org: home of the SME Server

CGI-Bin help

Ralph

CGI-Bin help
« on: September 01, 2002, 03:05:32 AM »
I am having a problem getting even the simplest cgi to run under an ibay. Although I can run the included cgi's for the apcupsd just fine. I created an ibay called test, uploaded(as a mapped drive, not ftp) a simple hello world cgi file into the cgi-bin dir and set the proper permissions(755). I can run a command line syntax check on the file and it's fine, there are no trailing ^M's either. The ibay has dynamic content enabled also.

The contents of the file are displayed below:

#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print "Test
\n";  

I get an internal server error all the time and the error log displays:

[error] (2)No such file or directory: exec of /home/e-smith/files/ibays/test/cgi-bin/test.cgi failed

[error] [client 192.168.1.1] Premature end of script headers: /home/e-smith/files/ibays/test/cgi-bin/test.cgi

I tried  a number of other scripts and have the same problem. I tried the script on 5.5 and 5.1 and have the same problem. If anyone is great with cgi's and can help me out, I'd be glad to hear what I'm missing. TIA

Ralph

Luke Drumm

Re: CGI-Bin help
« Reply #1 on: September 02, 2002, 03:40:01 AM »
I'd suggest using the CGI libraries as a start. ( http://www.perlmonks.org has some good tutorials and the man pages online. The Perl Cookbook is also a briliant reference point. ).

In this case my suspicion lies with not flushing the buffer early enough.

Regards,
Luke

Greg Zartman

Re: CGI-Bin help
« Reply #2 on: September 02, 2002, 08:01:08 PM »
A couple of troubleshooting ideas:

1.  Make sure you can run the script from the command line:  Terminal into your server and execute the script (e.g. at command prompt, input perl yourscriptname).  In the case of the example you listed above, you should see the following displayed:
Content-Type: text/html
[newline]
[newline]
Test


2.  Make sure you have set the ibay to allow "execution of dynamic content" (i.e., cgi scripts).  You'll find this option in the server-manager information bays panel, under the modify link.  I believe SME defaults to setting this option at diabled.

3.  Double check that your perl script has the path to perl "shebang" at the top of your script.  It should be #!/usr/bin/perl

4.  Make sure the file extension for your script are either .pl or .cgi.  

5.  Check your file permissions.  They should read identical to this example:
[root@server cgi-bin]# ll formmail.pl
-rwxr-x--x    1 admin    shared      26516 Aug 23 13:42 formmail.pl
[root@server cgi-bin]#

6.  Attempt to execute the script from your web browser by inputting the URL:  www.yourdomain.com/ibayname/cgi-bin/scriptname.pl

If none of this works, then  I'm guessing you have a system configuration issue.

Greg

Ralph

Re: CGI-Bin help
« Reply #3 on: September 05, 2002, 06:36:27 AM »
Hi Luke,

Thank you for replying, I did try to test your suggestion as I found some code on O'Reily's site that allows you to wrap up your print statements so the buffer is flushed each time a print statement is executed by the web server. However I still get the same Internal Server Error. Hopefully, I'll get to the bottom of this problem shortly.

Ralph

Ralph

Re: CGI-Bin help
« Reply #4 on: September 05, 2002, 06:45:00 AM »
Hi Greg,

First, thank you for being so clear on your steps for setting up a cgi script(that's a keeper). As you can see from my post, I did everything that you mention in those steps(did you get formmail to work?). I also went straight to Apache's website and used their how-to located here:

http://httpd.apache.org/docs/howto/cgi.html

This is the code I used:

    #!/usr/bin/perl
    print "Content-type: text/html\r\n\r\n";
    print "Hello, World.";

I don't think it's a server configuration problem on my part but at this point I'm not taking any chances. I proceeded to give it a try on a fresh install of SME 5.5 in server only mode. I cannot get this code to work, but I am grateful that you and Luke did try to help me, thanks again.  

Ralph

Shawn

Re: CGI-Bin help
« Reply #5 on: April 09, 2003, 08:23:00 PM »
Hi.

This reply is to an old post, but I had the same problem and found the solution.

When you copy the script using a mapped drive in Windows, the end-of-line character is not correct and interferes with shebang line (at least). The shell doesn't know how to execute the script.

If you use ftp instead, it should work. You still need to change the permissions on the script. eg. chmod 751 testscript.pl

Shawn