CGI/Fast CGI

software development

#1

I’m trying to run some CGI scripts on DreamHost. I’ve checked the support FastCGI box, but I get server 500 errors when I open the .cgi pages in web browsers. Does anyone have exact instructions on how to install CGI/Fast CGI on DreamHost? I’ve already looked at the Wiki, I’ve already contacted support. Thanks.


#2

Of course, there are a great many things that can cause that, and with no more information than you have provided, trying to discern what the problem might be would only be a guess. :wink:

Without seeing any of your code, or your error message in your error log, it could be anything. In my experience, on Dreamhost, the usual suspects are:

  1. Incorrect Permission on executable file - should be 755 on Dreamhost due to use of suexec.

  2. Incorrect shebang! line in perl script.

  3. Executable script file with non-*nix line endings (or other “borkedness” such as not uploading in ASCII mode)

Again, without the contents of your error logs or your code, these are all just guesses.

You should not have to mess with any of that, CGI/FastCGI support is already installed on all accounts by default - you can “toggle” FastCGI on/off in the control panel, as yo have already discovered.

–rlparker


#3

Here’s the code I’m using to test it. Error logs, I don’t have right now.

#!/usr/bin/perl

print “Content-type: text/html\n\n”;

print <<END_HTML;

Hello, World! END_HTML

Do you have any test code that should work? Thanks for your reply, by the way!


#4

No problem, though I don’t think I’m gonna be of much help - That code executes flawlessly on my server space. Why can’t you get at your error log?

Again, make sure that the dir, and the file itself has 755 permissions, make sure it is in proper *nix format - I don’t know what else to say, as that code (properly installed) works fine. :wink:

–rlparker


#5

I was confused about the logs. We hardly use them. The logs are below, and I know nothing about CGI. I’ve used it before with other hosts and it worked fine with the scripts that I used. I installed it by uploading the script in the DreamHost ftp upload manager. The extension is .cgi The entire directory was changed again, just to make sure it’s at 755.

The logs are below. I had to remove the usernames that appear in the logs for legal purposes, but if you need to know the setup, clientnameomitted is the domain name.

[Wed Apr 11 15:36:32 2007] [error] [client 221.152.139.220] Premature end of script headers: 1.cgi
[Wed Apr 11 15:36:32 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/internal_error.html
[Wed Apr 11 15:58:40 2007] [error] [client 221.152.139.220] Premature end of script headers: 2.cgi
[Wed Apr 11 15:58:40 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/internal_error.html
[Wed Apr 11 15:58:48 2007] [error] [client 221.152.139.220] (2)No such file or directory: FastCGI: stat() of “/home/clientnameomitted/clientnameomitted.com/2.fcgi” failed
[Wed Apr 11 15:58:48 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/missing.html
[Wed Apr 11 15:58:52 2007] [error] [client 221.152.139.220] Premature end of script headers: 2.cgi
[Wed Apr 11 15:58:52 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/internal_error.html
[Wed Apr 11 19:11:05 2007] [error] [client 221.152.139.220] client denied by server configuration: /home/clientnameomitted/clientnameomitted.com/ns2/template
[Wed Apr 11 19:11:05 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/forbidden.html
[Wed Apr 11 19:11:39 2007] [error] [client 221.152.139.220] client denied by server configuration: /home/clientnameomitted/clientnameomitted.com/ns2/template/main.html
[Wed Apr 11 19:11:39 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/forbidden.html
[Wed Apr 11 19:11:45 2007] [error] [client 221.152.139.220] client denied by server configuration: /home/clientnameomitted/clientnameomitted.com/ns2/template/main.htm
[Wed Apr 11 19:11:45 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/forbidden.html
[Wed Apr 11 19:12:26 2007] [error] [client 221.152.139.220] client denied by server configuration: /home/clientnameomitted/clientnameomitted.com/ns2/template/main.html
[Wed Apr 11 19:12:26 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/forbidden.html
[Wed Apr 11 19:13:09 2007] [error] [client 221.152.139.220] client denied by server configuration: /home/clientnameomitted/clientnameomitted.com/ns2/template/main.html
[Wed Apr 11 19:13:09 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/forbidden.html
[Wed Apr 11 19:29:44 2007] [error] [client 221.152.139.220] client denied by server configuration: /home/clientnameomitted/clientnameomitted.com/ns2/template
[Wed Apr 11 19:29:44 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/forbidden.html
[Wed Apr 11 19:30:30 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/template
[Wed Apr 11 19:30:30 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/missing.html
[Wed Apr 11 19:32:37 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/main
[Wed Apr 11 19:32:37 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/missing.html
[Wed Apr 11 19:44:26 2007] [error] [client 221.152.139.220] failed to open log file
[Wed Apr 11 19:44:26 2007] [error] [client 221.152.139.220] fopen: Permission denied
[Wed Apr 11 19:44:26 2007] [error] [client 221.152.139.220] Premature end of script headers: 2.cgi
[Wed Apr 11 19:44:26 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/internal_error.html
[Wed Apr 11 19:53:37 2007] [crit] [client 221.152.139.220] (13)Permission denied: /home/clientnameomitted/clientnameomitted.com/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Wed Apr 11 19:53:37 2007] [crit] [client 221.152.139.220] (13)Permission denied: /home/clientnameomitted/clientnameomitted.com/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Wed Apr 11 19:53:45 2007] [crit] [client 221.152.139.220] (13)Permission denied: /home/clientnameomitted/clientnameomitted.com/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Wed Apr 11 19:53:45 2007] [crit] [client 221.152.139.220] (13)Permission denied: /home/clientnameomitted/clientnameomitted.com/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Wed Apr 11 19:54:34 2007] [error] [client 221.152.139.220] failed to open log file
[Wed Apr 11 19:54:34 2007] [error] [client 221.152.139.220] fopen: Permission denied
[Wed Apr 11 19:54:34 2007] [error] [client 221.152.139.220] Premature end of script headers: 2.cgi
[Wed Apr 11 19:54:34 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/internal_error.html
[Wed Apr 11 19:54:36 2007] [error] [client 221.152.139.220] failed to open log file
[Wed Apr 11 19:54:36 2007] [error] [client 221.152.139.220] fopen: Permission denied
[Wed Apr 11 19:54:36 2007] [error] [client 221.152.139.220] Premature end of script headers: 2.cgi
[Wed Apr 11 19:54:36 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/internal_error.html
[Wed Apr 11 19:54:36 2007] [error] [client 221.152.139.220] failed to open log file
[Wed Apr 11 19:54:36 2007] [error] [client 221.152.139.220] fopen: Permission denied
[Wed Apr 11 19:54:36 2007] [error] [client 221.152.139.220] Premature end of script headers: 2.cgi
[Wed Apr 11 19:54:36 2007] [error] [client 221.152.139.220] File does not exist: /home/clientnameomitted/clientnameomitted.com/internal_error.html


#6

It looks like several things are likely going on here, and I suggest you approach them one at a time:

  1. the .cgi files (that are not relying on fastcgi) - The premature end of script headers - not real informative error message :wink: but is often the result of corrupted or incorrect format files - the first thing I would try with that is to dump the use of the net2ftp php application and try uploading them with a real ftp client and making sure that is done in ASCII mode, and with proper *nix line endings.

  2. It looks like your paths are messed up (see the “file does not exist” errors)

  3. There may also be permission errors on files the code needs to use (from the series of files being run, and no look at the code) your guess is better than mine as to what this might be.

In short, this looks like a “multi-file” application, where some parts depend on others - I couldn’t begin to debug it in this manner. The main.htm, and main.html, and others "is “template” a directory or a “file”? , etc. - this needs to be looked at with an understanding of how it all works together - and I have no way to do that. :frowning:

First, were you ever able to get the test code in your earlier post to fun? - start there - if you can’t get that to work, there is something fundamentally wrong with the way you are going about running these files. If you can get that sorted, you will have a basis from which to start figuring out how to configure your production files. :wink:

Additionally, you might consider enlisting the aid of someone who is perl/CGI savvy - the problems are likely not too difficult to resolve by someone with the requisite knowledge and who has access to the whole site/application files/ directories, etc. -

That all said, if these are “custom” scripts - you should enlist the aid of their author for getting them installed on DH - if they are a commercial product - you might try the support mechanisms of the company that sold you the scripts. I suspect that, for someone who has complete access, and installation instruction for the application, there should be little problem in getting then to run on DH - certainly, getting the perl scripts to run is likely to be far less problematic than if they were PHP scripts - Someone who knows about perl and cgi just needs to work through the whole setup.

–rlparker


#7

I believe this line says it all:

As stated here

[quote]
The PHP option allow_url_fopen would normally allow a programmer to open, include or otherwise use a remote file using a URL rather than a local file path. For security reasons, DreamHost has disabled this feature; however, a feature-rich alternative exists in the form of the bundled cURL library, and you can always get around the problem by compiling your own version of PHP.[/quote]

Hopefully that gives you an idea of how to solve your problem anyways… I know very little about programming such things myself.


#8

Mousee,

I could be wrong here (though I don’t think so)- but I believe he is running perl, and the fopen in the error message is a perl error message that is unrelated to the allow_url_fopen situation in PHP :wink:

–rlparker


#9

Thanks for your help.

What I did was paste everything between the stars-as is-into notepad, then uploaded it with SmartFTP in ASCII mode. I didn’t replace ‘usr’ with my username. I didn’t change anything. Is anything in that script supposed to be changed?


#!/usr/bin/perl

print “Content-type: text/html\n\n”;

print <<END_HTML;

Hello, World! END_HTML ; *****************************

The file name was 2.cgi now I’ve added another file named 2.pl just in case I was saving with the wrong extension. Those are the names that I saved them as and also the file name that I entered in the address bar. When running both scripts, the error in the error log is “Premature end of script headers.” The error that I get when visiting the pages:


Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@clientnameomitted.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.



#10

Well, at least now we are getting somewhere! :slight_smile: Notepad is most likely your problem! As I said in my previous posts, you must have *nix style line endings in your script or you will have problems, a very common one is the “premature end of script headers”.

The line endings Notepad used in your saved file are not correct for *nix systems (Windows/dos uses cr/lf pair of characters, and *nix wants only the lf). You can correct this in one of three ways:

  1. Use an editor capable of saving files with nix style line endings - there are many free editors around that do this, and everyone has their favorite - I like, and highly recommend the AEdiX Suite (free!) (which you can configure on the fly to save in *nix, Win/dos, or Mac line endings from the toolbar). I believe this is the best way to address this problem.

  2. run the “dos2unix” command in the shell to convert the file from dos line-endings to *unix line-endings on the server. For usage instructions, type “man dos2unix” (cr) at the shell prompt. This is not nearly as convenient as just using an editor that can save “*nix” files, but will do in a pinch.

  3. Find an ftp program that has this functionality built in (there are several), so that the file can be converted as necessary during the upload process. According to this information from the smartFTP forums, smartFTP can “automagically” convert line endings, but it is not totally intuitive, and you will need to check your setting to get it to perform in that manner for various filetypes. While this can be helpful, I prefer either of the previously listed methods for working with *nix files to this method.

I just took the code you provided in this last post, uploaded it, set it’s permission to 755 (the directory’s permissions also need to be 755), and ran it with success. The only difference between my results and yours is the editor - Notepad is a windows tool, and you need *nix line-endings. Fix that, and use correct permissions, and your “test” script will run properly. :wink:

You might also find this tutorial, or one of the many like it readily available on the net, to be useful.

–rlparker


#11

Thanks! I only got the dos2unix command to work on one .pl file. Other .pl files (even copies of the first) and .cgi files are not affected. I still get the error. Any ideas? Thanks for your help.


#12

Were you able to successfully run the “test” code that you posted in your previous posts?

–rlparker


#13

Permissions issue. I forgot to change them on the new files that I created. It works now. Thanks so much for your help!


#14

AH! That was my next guess, and the purpose of my question :wink: I’m glad you are making progress, and I’m glad I was able to be of some help. Hopefully, now you can make some progress in debugging the other files’ problems! As you do so, don’t forget to review a perl/cgi troubleshooting tutorial or two (like the link I provided) - they can be very helpful. Good Luck! :slight_smile:

–rlparker