Hai, I was trying to run a CGI cript that proccessed people's information... Well anyway I kept getting the very unhelpful Internal Server Error So I decided to make a stupid script that merely displayed "Works" To the screen. I contacted my webserver (1and1.com) they told me perl scripts could be run anywhere from the server as long as they had a .pl/.cgi extension and were chmoded to 755. 1and1 also said that the path for perl was /usr/bin/perl so the first line of the script would be #!/usr/bin/perl. I made the file:

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

I saved the file as display.cgi, I put it on my webserver under /AxE/ directory chmoded to 755 and it still gave me "Internal Server Error" I then just to check made a cgi-bin folder and put it there and still the same error... I'm going crazy and am out of ideas, if anyone could help they would be garanteed a spot as my hero


PS: I also tried saving it as .pl not chmoding and i also tried chmoding while it was in the cgi-bin directory which I was told is not needed. I also tried googling hello world examples incase maybe I had a coding bug... :-\


PSS: I posted this on another forum and basicly recieved no help, well i guess i learned that merely creating a cgi-bin folder does nothing, and i knew this already however I thought that my webserver would see the folder and set it up as a ScriptAllias. another thing that should be noted is i double adn triple checked and on my webserver it states that scripts can be put anywhere as long as they have a .pl or .cgi extension are uploaded under ascii mode and are chmoded to 755. Infact my acnt didn't even come with a cgi-bin folder.

Well, yes, seemingly they can run from everywhere, or you wouldn't be getting an internal server error, but rather the contents of the script spilled out onto the browser (or the browser asking you what you wanted to do with ".pl" file).

As to why it is failing, hard to say. I would say to send 1and1 a copy of your simple example and ask them why it might be failing.

Another thing to try, when it is a perl file, they may have something that checks that you are actually running in "Taint" mode (i.e. /usr/bin/perl -T) and when you are not fail your script in some way. I don't know if you have tried this already, but make an attempt at using -T.

Also, do have access to logs anywhere. The logs should have some better explanation as to what went wrong with your script.

how did you put your file onto the server? did you upload it in ASCII mode? binary mode wont work. I had big problems using Windows FTP as it assumes the filetype and doesn't seem to have any options.. try uploading the file using your domains control panel if you have one, or if you have a reasonable FTP client, just make sure it's in ASCII mode whenever you upload a Perl script.

MattEvens, I do most of my stuff when i'm on computers that I can't really download stuff with so I just use the Dos Box and yes I typed ascii at the prompt before putting the script on my server. Thanks for the advice though. Masijade useing taint checking is a good idea >.< I feel like a huge idiot for overlooking it... it's quite pssible 1and1 requires it for security, then again it should have told me that when I read about CGI/perl on their FAQ's. I'm going to go try this now..... any other ideas would be great.

EDIT: I'll post back on wether it worked or not in like 10-15mins

Ugh.. Ok i'm officially going crazy... I tried with -T on and still the same completely unhelpfull error msg!

i tried uploading your script, from dos, to an apache and an IIS server. it worked fine both times.

what editor did you save your file using? the editor could have put incorrect line terminators, that's quite unlikely though =S

i've attached a file, test.txt. rename it to test.pl, open it to look at it by all means but don't re-save it.

try uploading that, it worked the first time on both servers, i didn't even need to change permissions.

EDIT: by the way, if the Error 500 screen really annoys you (it really annoys me), add this use to any script functioning as a CGI:

use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;

but of course, if Perl can't run, Perl can't use CGI::Carp.

Attachments
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Works";

Hello,

This problem was posted a long time ago, but I also run my Perl/CGI scripts from a 1and1 web server... The reason your script isn't working is because you must use CGI standard and some of the time, strict. Web based Perl scripting is called CGI, (although it doesn't matter whether you use the extension .pl or .cgi), and if you are using declarations such as "Content-type: text/html\n\n", obviously html is a web based code, therefore comes under CGI. FOR EVERY SINGLE SCRIPT YOU WRITE ALWAYS START WITH #!/usr/bin/perl use strict; use CGI ':standard';. People who said they ran your code and it worked were right, because their system doesnt require to use CGI Standard. To learn more, look for books on CGI, not Perl. (CGI For the World Wide Web)

#!/usr/bin/perl
use strict;
use CGI ':standard';
print "Content-type: text/html\n\n";
print "Works";

That is the solution...

Chris

Hi Chris,

try this on your 1and1 server:

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

it should work. The CGI module does not have to be loaded to run a CGI script.

Hi Kevin,

Your right, it does work!

However, if I try a different script which uses a range of Perl functions, it doesn't work, unless I declare use of CGI Standard. I've never ever tested a simple print script before.

So I guess heres some other tips which have probably already been suggested:
1) Chmod your script with permissions 755 (on 1and1 Webspace Explorer, right click the script file, and then permissions).
2) Upload your scripts in ASCII format (which is default on 1and1 Webspace Explorer).
3) ALWAYS use lowercase letters in your script file name, this may not always be a problem, but sometimes the script will not work properly. Its just a good habit to have in case future scripts do not work. I.e. use script.pl NOT Script.pl
4) Of course, always declare print "Content-type: text/html\n\n"; before printing a statement in CGI.
5) Use a syntax checker to check that your syntax is good. I.e. http://ult-tex.net/tools/ultra/line_count.pl. 1and1 package also comes with a syntax checker, but if you are using the Webspace Explorer (not FTP), then you can't have both open at once, so its easier to use an external syntax checker.
6) 1and1 package comes with a CGI Output Monitor. Open it, locate the directory the script is in, type in the script file name, ignore the parameter option unless you know the parameter. Even when syntax is correct (or not), this often provides a more in-depth reason why your script isn't working. It will also check if the server is connecting to your script properly, and warn you etc etc.

There are a few other things you could check, but the above are most important.

Chris

This article has been dead for over six months. Start a new discussion instead.