PDA

View Full Version : Perl files doesn't start.



enginaar
06-14-2004, 12:38 AM
Hello,

I've a mymd5.pl perl script under /cgi-bin dir but i can't use it on web. cgi-bin directory's permissions are set by 755. What must i do.

sander815
06-14-2004, 12:39 AM
same for me, can't get perl scripts to run....

enginaar
06-14-2004, 12:40 AM
I get 500 Internal Server Error.

l0rdphi1
06-14-2004, 02:16 AM
Hello,

1/ Make sure the Perl script has \n break format:
perl -pi -e "s/\r\n/\n/g" youfile.pl
2/ The directory your Perl script resides in must be chowned and chgrped to the user who is running the script (The dir can not be user:apache!!)

3/ Make sure the Perl script itself is chmod 755

4/ ExecCGI must be enabled (via httpd.conf or .htaccess) in the directory you've placed the Perl script

That will usually fix most problems :)

Phi1.

enginaar
06-14-2004, 03:03 AM
If it helps you to find out the problem, i've an output of perl -c command below.


Can't locate CGI.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .) at /home/user/public_html/cgi-bin/samplechk.pl line 3.
BEGIN failed--compilation aborted at /home/user/public_html/cgi-bin/samplechk.pl line 3.


I was running this script on my older machine that was running Ensim and Perl 5.6.0. I've had no config to it, it was running with default configuration. There is a /usr/lib/perl5/5.6.0/CGI.pm file on the older machine but i can't find it in my new mach.

Can it be done if i copy the CGI.pm file to the /usr/lib/perl5/5.8.0 directory.

l0rdphi1
06-14-2004, 03:14 AM
Hello,

You'll want to use CPAN to install the CGI module:

# perl -MCPAN -e shell
cpan> install CGI

Phi1.

enginaar
06-14-2004, 03:54 AM
Thanks its working, but i've another problem now.

My protected directories doesn't work.

I checked .htaccess and .htpasswd files and they are OK but i can't view protected directories from web without using any password.

enginaar
06-14-2004, 04:54 AM
Another problem about cgi again. I've find a counter.cgi and want to run it, perl -c counter.cgi output is Syntax OK, but there is a strange string in the error log, when i want to open from web.

Premature end of script headers: /home/user/domains/domain.com/public_html/cgi-bin/counter.cgi

sander815
06-14-2004, 07:24 AM
having exactly same problems
perl -c script.cgi: syntax ok
when calling the script with explorer, 500 error

error log: [Mon Jun 14 16:26:02 2004] [error] [client 195.xxx.xx.xxx] Premature end of script headers: /home/strandju/domains/xxx/public_html/cgi-bin/perldiver.cgi

sander815
06-14-2004, 07:42 AM
running the script as root gives me a bunch of html code, so its working

enginaar
06-14-2004, 07:59 AM
What did you mean exactly, i couldn't understand. Running root what. Do i have to set owner of the cgi script root:root.

sander815
06-14-2004, 11:35 AM
no, i mean, when i login as root(ssh)
i run:
$perl <scriptname>.cgi i get html code, so seems to me its working, no errors



[root@server01 cgi-bin]# perl perldiver.cgi
Content-Type: text/html; charset=ISO-8859-1

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"><head><
title>Perl Diver : Main</title>
<style type="text/css">
<!--/* <![CDATA[ */
body {
etc. etc.

when i call the script through the domainname with exploorer i get:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request. etc

l0rdphi1
06-14-2004, 02:22 PM
Originally posted by l0rdphi1
Hello,

1/ Make sure the Perl script has \n break format:
perl -pi -e "s/\r\n/\n/g" youfile.pl
2/ The directory your Perl script resides in must be chowned and chgrped to the user who is running the script (The dir can not be user:apache!!)

3/ Make sure the Perl script itself is chmod 755

4/ ExecCGI must be enabled (via httpd.conf or .htaccess) in the directory you've placed the Perl script

That will usually fix most problems :)

Phi1.
;) -- I bet the problem is one of those.

enginaar
06-15-2004, 06:19 AM
How can i make sure it if it has \n break format. Or how can i change it to that format.

Is this error message: "Premature end of script headers" related to the \n break format?

nobaloney
06-15-2004, 08:24 AM
Originally posted by enginaar
How can i make sure it if it has \n break format.
Upload it as ascii.

Or how can i change it to that format.
If you've got shell access and if dos2unix is installed on your server, navigate to the subdirectory where the cgi program is located and then do:

$ dos2unix filename

where filename is the name of the file you're converting.

Is this error message: "Premature end of script headers" related to the \n break format?
Do a google on the error message to see some possible causes and fixes.

Jeff

RosT
07-12-2004, 12:59 AM
Originally posted by l0rdphi1
Hello,

1/ Make sure the Perl script has \n break format:
perl -pi -e "s/\r\n/\n/g" youfile.pl
2/ The directory your Perl script resides in must be chowned and chgrped to the user who is running the script (The dir can not be user:apache!!)

3/ Make sure the Perl script itself is chmod 755

4/ ExecCGI must be enabled (via httpd.conf or .htaccess) in the directory you've placed the Perl script

That will usually fix most problems :)

Phi1.

All ok! But, script via domain name don't work. What to do?

RosT
07-12-2004, 01:03 AM
Siple script don't work:

#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "All work";

thuskey
07-12-2004, 05:29 AM
Originally posted by RosT
Siple script don't work:

#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "All work";

Check your "AddHandler cgi-script .cgi .pl" line in your httpd.conf file if your trying to run it outside of cgi-bin.

with temporary ftp access, I can help more. Let me know if you need further assistance.

thuskey
07-12-2004, 09:43 AM
simple fix...

/usr/bin/perl is linked to /usr/local/bin/perl which is missing.

recreate link with "ln -s /usr/bin/perl5 /usr/bin/perl"

Not exactly sure why perl 5.8 was installed and is now missing, but you should consider reinstalling perl 5.8 in the long run.