problems running script

james99

Verified User
Joined
Jul 24, 2004
Messages
21
I'm trying to get a script to run but it refuses to cooperate.

I have the public_html directory chmod 777. The file is chmod 755 and owned by the user. I have an .htaccess file with Options +ExecCGI so I can run outside of the cgi-bin.

If I run it via ssh as "perl filename.cgi" it outputs the correct html. But when I view it in my browser I get a 500 internal server error. The error log only contains a "Premature end of script headers".

Any ideas what could be causing this? It's frustrating. :(
 
Hey,

Did you have a content type set in your script? Like so:

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

David
 
Yup.

[root@server2 www]# perl log-in-page.cgi
Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

...

Is that a good thing or a bad thing?
 
Thats a good thing.

I see when you run it on the command line, you call perl specifically. Does the first line of the script look exactly like this?

#!/usr/bin/perl

If so, see if the program will work from the command line with just "./filename.cgi" without the perl call.
 
make sure the user can "run" it. If you create the script as root, you must "chown" it.
 
GNU nano 1.2.1 File: log-in-page.cgi

#!/usr/bin/perl

-rwxr-xr-x 1 nervousn nervousn 6326 Dec 22 2003 log-in-page.cgi

[root@server2 www]# ./log-in-page.cgi
Content-type: text/html

Let me switch to the user and try it.
[nervousn@server2 public_html]$ ./log-in-page.cgi
Content-type: text/html

-rwxr-xr-x 1 nervousn nervousn 6326 Dec 22 2003 log-in-page.cgi

GNU nano 1.2.1 File: log-in-page.cgi

#!/usr/bin/perl

I'm totally stumped.
 
Or you can try to run a very simple script just output a string 'hello world!', to make sure it can run CGI script actually!
 
[root@server2 www]# ./cgi-test.cgi
Hello World[/qute]

Yet, via http it gives internal server error.

Hmm. Wait! I think I might've figured it out.

I'm still in the process of moving files over to the DA server (previously used cPanel), so I haven't changed the DNS yet.

I've been accessing the site via http://hostname/~user/

Could that be causing the problem?

If so, any suggestion for how I can finish tweaking the scripts without changing the DNS just yet?
 
It needs to be in the CGI-BIN. I had similar problems, and using the CGI-BIN was the only solution.

Matt
 
Scripts do not necessarily have to be in cgi-bin.

They can be in any directory as long as the directory also contains a .htaccess file with the following two lines:

Options +ExecCGI
AddHandler cgi-script .cgi .pl

Jeff
 
OK, I changed my .htaccess and it still gives the error.

I moved cgi-test.cgi to the cgi-bin which consists of just:

#!/usr/bin/perl

print "Hello World\n"

and that script when accessed via http in the cgi-bin gives the error.

:(
 
Will you...

Show us the "ls -al" output for the cgi-bin directory holding the test.cgi.

Give us the real web-path to the file so we can test it.

:confused:

Do any other cgi programs for this site work?

Do any other cgi programs on the server work?

Jeff
 
[root@server2 public_html]# ls -al
total 26204
drwxrwxrwx 25 nervousn apache 4096 Jul 25 20:30 .
drwx--x--x 8 nervousn nervousn 4096 Jul 23 00:10 ..
drwxr-xr-x 2 nervousn nervousn 4096 Jun 5 10:16 a
drwxr-xr-x 2 nervousn nervousn 4096 Jul 5 21:08 about
drwxr-xr-x 3 nervousn nervousn 4096 Jul 11 23:06 admin
-rw-r--r-- 1 root root 0 Jul 25 20:30 a.out
-rw-r--r-- 1 nervousn nervousn 1296 Jan 5 2004 backup.php
drwxr-xr-x 2 nervousn nervousn 4096 Jul 25 18:27 cgi-bin
-rwxr-xr-x 1 nervousn nervousn 3547 Nov 10 2002 comment.cgi
-rwxr-xr-x 1 nervousn nervousn 57569 Jun 18 2003 convert.pl
drwxr-xr-x 2 nervousn nervousn 4096 Dec 22 2003 css
-rw-r--r-- 1 nervousn nervousn 3490 Nov 10 2002 db-down.html
-rw-r--r-- 1 nervousn nervousn 302 Jul 24 10:43 db.php
drwxr-xr-x 2 nervousn nervousn 4096 Dec 10 2002 debates
-rw-r--r-- 1 nervousn nervousn 2826 Nov 10 2002 decima.html
drwxr-xr-x 2 nervousn nervousn 4096 Dec 18 2002 email
-rwxr-xr-x 1 nervousn nervousn 1328 Nov 10 2002 email-addresses.cgi
drwxr-xr-x 3 nervousn nervousn 4096 Dec 22 2003 faq
-rw-r--r-- 1 nervousn nervousn 240 Jan 28 07:36 favicon.ico
-rwxr-xr-x 1 nervousn nervousn 178 Nov 10 2002 foo.cgi
-rw-r--r-- 1 nervousn nervousn 2321 Jun 3 03:06 forgot.php
-rwxr-xr-x 1 nervousn nervousn 3290 Nov 10 2002 forgotten_password.cgi
-rw-r--r-- 1 root root 26399841 Jun 8 00:27 hp.exe
-rw-r--r-- 1 nervousn nervousn 48 Jul 25 18:26 .htaccess
drwxr-xr-x 6 nervousn nervousn 4096 Jul 22 14:13 images
-rwxr-xr-x 1 nervousn nervousn 16697 Jan 30 2003 imbue.cgi
-rwxr-xr-x 1 nervousn nervousn 9186 Nov 10 2002 index2.cgi
-rwxr-xr-x 2 nervousn nervousn 73 Jul 24 2003 index.cgi
-rwxr-xr-x 1 nervousn nervousn 2224 Jul 24 2003 index.old
-rw-r--r-- 1 nervousn nervousn 11144 Nov 10 2002 index-old.html
-rw-r--r-- 1 nervousn nervousn 5720 Jul 24 10:51 index.php
-rw-r--r-- 1 nervousn nervousn 18 Mar 19 11:25 info.php
drwxr-xr-x 2 root root 4096 Jan 28 07:39 js
-rw-r--r-- 1 nervousn nervousn 98 Nov 10 2002 libraries.lib
drwxr-xr-x 2 nervousn nervousn 4096 Aug 3 2003 lmao
-rwxr-xr-x 1 nervousn nervousn 6326 Dec 22 2003 log-in-page.cgi
drwxr-xr-x 2 nervousn nervousn 4096 Feb 12 22:19 mockup
drwxr-xr-x 2 nervousn nervousn 4096 Jul 20 2003 mockup2
-rwxr-xr-x 2 nervousn nervousn 73 Jul 24 2003 nervous.cgi
drwxr-xr-x 3 nervousn nervousn 4096 Dec 10 2002 new
-rwxr-xr-x 1 nervousn nervousn 2937 Nov 10 2002 new.cgi
-rwxr-xr-x 1 nervousn nervousn 2574 Nov 10 2002 new-index.cgi
-rwxr-xr-x 1 nervousn nervousn 4009 Nov 10 2002 new-log-in-page.cgi
-rw------- 1 nervousn nervousn 97 Jul 20 2003 news.php.save
-rw-r--r-- 1 nervousn nervousn 4307 Dec 18 2002 nv-mockup.html
-rw-r--r-- 1 nervousn nervousn 9315 Dec 17 2002 nv-new-layout-mockup.gif
-rwxr-xr-x 1 root root 2915 Jul 22 13:18 old-index.cgi
drwxr-xr-x 2 nervousn nervousn 4096 Nov 10 2002 open
drwxr-xr-x 4 nervousn nervousn 4096 Nov 25 2003 people
-rw-r--r-- 1 nervousn nervousn 633 Jul 24 2003 privacy.php
drwxr-xr-x 2 nervousn nervousn 4096 Nov 10 2002 products
-rwxr-xr-x 1 nervousn nervousn 653 Nov 17 2002 profile.cgi
-rw-r--r-- 1 nervousn nervousn 1042 Sep 7 2003 question.phps
drwxr-xr-x 2 nervousn nervousn 4096 Dec 10 2002 questions
-rw-r--r-- 1 nervousn nervousn 80 Jul 12 16:26 redirect.php
-rw------- 1 nervousn nervousn 283 Jan 27 00:57 robots.txt.save
-rw-r--r-- 1 nervousn nervousn 159 Dec 22 2003 script.php
-rw-r--r-- 1 nervousn nervousn 1206 Oct 27 2003 server_script.php
drwxr-xr-x 4 nervousn nervousn 4096 Nov 20 2003 shop
drwxr-xr-x 4 root root 4096 Oct 20 2003 shop2
drwxr-xr-x 8 nervousn nervousn 4096 Jan 9 2004 store
drwxr-xr-x 2 nervousn nervousn 4096 Oct 10 2003 subscribe
-rw-r--r-- 1 nervousn nervousn 180 May 26 22:49 suspend.php
-rw-r--r-- 1 nervousn nervousn 4367 Nov 12 2003 temp.php
-rwxr-xr-x 1 nervousn nervousn 1316 Nov 10 2002 test.cgi
drwxr-xr-x 2 nervousn nervousn 4096 Jul 10 2003 tmpl
-rw-r--r-- 1 nervousn nervousn 4059 Jul 12 23:03 unsubscribe.php
-rw-r--r-- 1 nervousn nervousn 35 Jul 21 2003 __utm.gif
-rw-r--r-- 1 nervousn nervousn 1141 Jul 21 2003 __utm.js
-rw-r--r-- 1 nervousn nervousn 254 Dec 3 2003 yourpage.php
[root@server2 public_html]#

http://server2.nervousness.org/~nervousn/log-in-page.cgi
http://server2.nervousness.org/~nervousn/cgi-bin/cgi-test.cgi

Nope, no CGI works for this site. PHP does, not that that matters since the majority of the site is in Perl and slowly being ported into PHP.

Um, not sure about server-wide as this is the only account on the server. Want me to create another and give it a whirl?
 
james99 said:
Why is the directory world writable?

The "." entry should be chmod 755, not 777.
Nope, no CGI works for this site. PHP does, not that that matters since the majority of the site is in Perl and slowly being ported into PHP.

Um, not sure about server-wide as this is the only account on the server. Want me to create another and give it a whirl?
First try making the cgi-bin directory chmod 755 and see if that makes a difference.

If that doesn't work, take a look at the apache error log for the site.

Jeff
 
changed to chmod 755, but it still gives the error.

[Sun Jul 25 04:02:04 2004] [notice] Apache/1.3.31 (Unix) mod_ssl/2.8.19 OpenSSL/0.9.7a PHP/4.3.8 mod_perl/1.27 FrontPage/5.0.2.2510 configured -- resuming normal operations
[Sun Jul 25 04:02:04 2004] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Sun Jul 25 04:02:04 2004] [notice] Accept mutex: sysvsem (Default: sysvsem)
[Sun Jul 25 18:27:08 2004] [error] [client 24.190.55.216] Premature end of script headers: /home/nervousn/public_html/log-in-page.cgi
[Sun Jul 25 18:27:08 2004] [error] [client 24.190.55.216] File does not exist: /var/www/html/500.shtml

:confused:
 
Or you may need to create another account and do the same things to test it out.

:)
 
OK, I created another account with:

username: testuser
domain: nervousness.us

Then I created a file using nano of just:

Code:
#!/usr/bin/perl

print "Hello World\n"

I did chmod 755.

Via SSH:

[testuser@server2 cgi-bin]$ ls -al
total 16
drwxr-xr-x 2 testuser testuser 4096 Jul 27 03:40 .
drwxr-x--- 25 testuser apache 4096 Jul 27 03:37 ..
-rw-r--r-- 1 testuser testuser 17 Jul 27 03:35 .htaccess
-rwxr-xr-x 1 testuser testuser 39 Jul 27 03:40 test.cgi
[testuser@server2 cgi-bin]$ ./test.cgi
Hello World
[testuser@server2 cgi-bin]$

But, it still gives 500 internal server error via http.

See it @ http://nervousness.us/cgi-bin/test.cgi
 
Well, first off you're going to need to print out the text/html header, i.e.:
Code:
#!/usr/bin/perl

print "Content-Type: text/html\n\nHello World\n"
Phi1.
 
Back
Top