CGI scripts causing 500 Internal Server error

webone

Verified User
Joined
Jan 17, 2004
Messages
59
We can't get any type of perl file to execute in our clients (or any other client on the server) cgi-bin directory. We've tried everything!

I've tried uploading a test.pl file which simply looks like this:

#!/usr/bin/perl
print "Hello World!\\n\";

We just get the 500 Internal Server error. The users username is globalnet and as you can see from the /var/log/httpd/suexec_log logs the file is owned by the correct user:

[2005-05-21 09:14:54]: info: (target/actual) uid: (globalnet/globalnet) gid: (globalnet/globalnet) cmd: test.pl

So . . . I tried navigating to the users cgi-bin directory via ssh and at the command prompt did:

./test.pl

which yielded:

: bad interpreter: No such file or directory

I made sure that the path to perl in the interpreter was correct. It was. I made sure the file actually existed. It does. I even tried renaming the file to test.cgi . . . made no difference.

I tried installing the the DBD mysql bundle which generated the following errors:

Cannot connect: Access denied for user: 'root@localhost' (Using password: NO)
Either your server is not up and running or you have no
permissions for acessing the DSN DBI:mysql:test.
This test requires a running server and write permissions.
Please make sure your server is running and you have
permissions, then retry.

AND

Cannot connect: Access denied for user: 'root@localhost' (Using password: NO)
It looks as if your server is not up and running.
This test requires a running server.
Please make sure your server is running and retry.

Any ideas? I'm completely stuck here!

Thanks!
 
Due to the error regarding the interpreter, it would seem to indicate that that is the problem. Have you tried reinstalling/building perl and mod_perl in apache.
Best getting it working from the command line before attempting it through apache.

If you add the location to perl in the execution command does it work?
 
Is there a ./update ./build way of doing that or do I have to do it through the command line? If so, how? I'm using RHEL 3.

Thanks!
 
It depends on how perl was originally installed on your system (source, packaged, etc).
mod_perl would be built through customapache.
 
Hello,

FreeBSD machines tend to have it in /usr/local/bin/perl, so as root, type:

Code:
ln -s /usr/local/bin/perl /usr/bin/perl

to create a symbolic link from your actual perl the the "normal" perl location (for linux machines)

John
 
Thanks for the input!

I tried this but to no avail I'm afraid . . . the error I get is:

ln: '/usr/bin/perl': File exists

Any more ideas?

Thanks again!


=====================
EDIT:
=====================

Thinking about your advice John . . . it doesn't make sense to me? I'm on RHEL and the perl binary is in /usr/bin so why would I want to create a a symbolic link that way round? I'm bound to get a a file exists aren't I? I tried it the other way round:

ln -s /usr/bin/perl /usr/local/bin/perl

So now there's a sym link in /usr/local/bin/ to perl in /usr/bin/ but this doesn't seem to have had an effect either?
 
Last edited:
Hello,

1) edit the file through the DA filemanager, then save it. There may be a windows ^M character at the end of the line (saving through the DA filamanger removes it).

2) test out perl:
Code:
echo "print \"hi\n\";" | /usr/bin/perl
/usr/bin/perl needs to exist and work (chmod 755).

John
 
Hi John,

Thanks for sticking with me. . .

I edited the file in da's file manager and saved it.

I made sure perl was working by entering

Code:
echo "print \"hi\n\";" | /usr/bin/perl

and the result was "hi" was printed to the console window, so perl *is* where it should be and it *is* working.

The file also has permission 755 tried changing it to 777 and various other permissions and nothing!

I've tried installing free perl scripts, a thousands different perl files and each time it comes up with the 500 internal error page.

I have 2 boxes with DA running on them and both have the same problem. On all client accounts too.

Any more ideas?

:(
 
Hello,

Then it points back to your script, or files/modules that it's including.

If you run it manually and you get the "bad interpreter" error.. then you'd need to sift through your script to see if it's including any other files that are using an invalid interpreter.

John
 
Hi,

I just don't understand. How can a two line perl script go wrong? And why is it happening with ALL perl scripts on ALL accounts? My test script again . . .

Code:
#!/usr/bin/perl
print "Hello World!\\n\";

The interpreter is *correct*. The code is *correct*. The permissions (755) are *correct*. The UID and GID are *correct*. Unless I've just been staring at it so long I can't see the mistake? If it were a syntax issue, why then would clients who were able to run perl scripts suddenly can't any longer?

Also, the bad interpreter message received when trying to execute the script from the command line says that neither the *file* nor the *directory* can be found???

Code:
: bad interpreter: No such file or directory

Can anyone help? Please? I'm willing to pay reasonable costs!

:confused:
 
Hello,

We've got a cgi debug tutorial here:
http://help.directadmin.com/item.php?id=6

Also, for the interpreter, you'd need to check your interpreter. Check for the actual file: /usr/bin/perl

Try running the script by hand:
cd /home/username/domains/domain.com/public_html/cgi-bin
./test.pl

You may have a windows newline character at the end of the #!/usr/bin/perl line, so edit it with vi, pico or nano to get rid of any weird ^M characters. (or just edit it through the DA filemanager and save it).

Also, for a test.pl file, you forgot the Content-Type header ;) (a *must* have for scripts), eg:
Code:
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print "Hello World!\n";
John
 
Well I had the same prob,
did a
$ perl -pi -e 's/\r\n/\n/' myscript.cgi

wala, fixed the bad line endings !

Thought it might help someone...

Glenn
 
same problem in uebimiau

lot of ^M
in uebimiau php files located at
/usr/home/var/www/html/webmail/inc/

how dit it get there?

try to remove...
 
Re: same problem in uebimiau

pera said:
lot of ^M
in uebimiau php files located at
/usr/home/var/www/html/webmail/inc/

how dit it get there?

try to remove...
Those are carriage returns (\r), and they are used in combination with new lines (\n) in the DOS/Windows world. This application was probably written on Windows and the carriage returns were never stripped off.

To remove them try doing what GlennH said, except instead of passing myscript.cgi pass the the file you want the ^M charcaters stripped from.
 
Many linux systems have a dos2unix command that will fix line-endings.

There's also a shebang line that will work to tell the perl interpreter to strip the lines as it reads the file, but I don't remember what it is.

:(

Jeff
 
Back
Top