PDA

View Full Version : problems running script


james99
07-24-2004, 03:00 AM
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. :(

skruf
07-24-2004, 05:52 AM
Hey,

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

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

David

james99
07-24-2004, 07:03 AM
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?

thuskey
07-24-2004, 08:11 AM
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.

jeffery
07-24-2004, 10:31 AM
make sure the user can "run" it. If you create the script as root, you must "chown" it.

james99
07-24-2004, 10:56 AM
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.

jeffery
07-24-2004, 10:58 AM
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!

james99
07-24-2004, 11:06 AM
[quote][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?

thuskey
07-24-2004, 10:31 PM
http://ipaddress/~user maybe?

james99
07-25-2004, 08:35 AM
Something is wrong here because I gave the account a dedicated IP, and accessing it at http://IP/log-in-page.cgi gives a 500 error as well.

Ugh. Any more ideas?

thoroughfare
07-25-2004, 09:59 AM
It needs to be in the CGI-BIN. I had similar problems, and using the CGI-BIN was the only solution.

Matt

jlasman
07-25-2004, 10:17 AM
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

james99
07-25-2004, 10:27 AM
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.

:(

jlasman
07-25-2004, 11:00 AM
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

james99
07-25-2004, 12:31 PM
[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?

jlasman
07-25-2004, 12:38 PM
Originally posted by james99
http://server2.nervousness.org/~nervousn/log-in-page.cgi
http://server2.nervousness.org/~nervousn/cgi-bin/cgi-test.cgi
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

james99
07-25-2004, 06:06 PM
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:

jeffery
07-25-2004, 11:21 PM
Or you may need to create another account and do the same things to test it out.

:)

james99
07-26-2004, 07:41 PM
OK, I created another account with:

username: testuser
domain: nervousness.us

Then I created a file using nano of just:

#!/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

l0rdphi1
07-26-2004, 09:37 PM
Well, first off you're going to need to print out the text/html header, i.e.:#!/usr/bin/perl

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

thuskey
07-27-2004, 06:15 AM
Originally posted by james99

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

James, I'm headed to a Avici certification class at the moment and don't have enough spare time to troubleshoot ths now, but what if I were to call you this evening, around 7pm central time? Would you have time to work this issue then? Just PM me your number, if it is in the US, or let me know a good time to catch you on skype, and I'll give you a call.

james99
07-30-2004, 11:45 AM
OK, an update!

I switched the DNS to start resolving to the new DA server, recreated the account, etc.

CGI now works in the cgi-bin (example (http://nervousness.org/cgi-bin/cgi-test.cgi)), but not outside of it (example (http://nervousness.org/cgi-test.cgi)),which it needs to for this site.

[root@server2 public_html]# ls -al
total 26228
drwxr-xr-x 28 nervousn apache 4096 Jul 30 19:33 .
drwx--x--x 6 nervousn nervousn 4096 Jul 30 07:30 ..
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 nervousn nervousn 1296 Jan 5 2004 backup.php
drwxr-xr-x 2 nervousn nervousn 4096 Jul 30 19:27 cgi-bin
-rwxr-xr-x 1 nervousn nervousn 66 Jul 30 19:33 cgi-test.cgi
-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
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 2004 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
drwxr-xr-x 3 nervousn nervousn 4096 Jul 30 07:30 forums
-rw-r--r-- 1 nervousn nervousn 26399841 Jun 8 00:27 hp.exe
-rw-r--r-- 1 nervousn nervousn 607 Jul 30 19:27 .htaccess
-rw-r--r-- 1 nervousn nervousn 121 Mar 16 06:29 .htaccess2
-rw-r--r-- 1 nervousn nervousn 121 Mar 16 06:16 .htaccess-block
drwxr-xr-x 6 nervousn nervousn 4096 Jun 5 02:09 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 4725 Jul 13 23:41 index.php
-rw-r--r-- 1 nervousn nervousn 18 Mar 19 11:25 info.php
drwxr-xr-x 2 nervousn nervousn 4096 Jan 28 2004 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
drwxr-xr-x 4 nervousn nervousn 4096 Jun 18 2003 .old
-rwxr-xr-x 1 nervousn nervousn 2915 Nov 10 2002 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
drwxr-xr-x 3 nervousn nervousn 4096 Jul 30 07:30 px
-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-r--r-- 1 nervousn nervousn 193 Jan 28 2004 robots.txt
-rw------- 1 nervousn nervousn 283 Jan 27 2004 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 nervousn nervousn 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[/url]

[quote] GNU nano 1.2.1 File: .htaccess

Options +ExecCGI
AddHandler cgi-script .cgi

Redirect permanent /forum-cgi/ikonboard.cgi http://forums.nervousness.org/index.php

Redirect permanent /about/suspension.php http://nervousness.org/log-in-page.cgi?logout=1

Redirect permanent /forums http://forums.nervousness.org

httpd.conf

<Directory /home/nervousn/domains/nervousness.org/public_html>
Options +Includes -Indexes ExecCGI
php_admin_flag engine ON
php_admin_flag safe_mode OFF
AddHandler cgi-script .pl .cgi
</Directory>

james99
07-30-2004, 11:48 AM
&&

error log:

[Fri Jul 30 19:34:05 2004] [error] [client 24.190.55.xxx] Premature end of script headers: /home/nervousn/domains/nervousness.org/public_html/cgi-test.cgi
[Fri Jul 30 19:34:05 2004] [error] [client 24.190.55.xxx] File does not exist: /home/nervousn/domains/nervousness.org/public_html/500.shtml


suexec log:

[2004-07-30 19:34:01]: info: (target/actual) uid: (nervousn/nervousn) gid: (nervousn/nervousn) cmd: cgi-test.cgi
[2004-07-30 19:34:05]: info: (target/actual) uid: (nervousn/nervousn) gid: (nervousn/nervousn) cmd: cgi-test.cgi
[2004-07-30 19:34:05]: error: target uid/gid (501/501) mismatch with directory (501/103) or program (0/0)

I really appreciate how helpful you all have been. I just wish I could get this darned thing up and running :p

skruf
07-30-2004, 01:55 PM
Hey,

Just curious what happens if you change the public_html to be nervousn:nervousn?

David

james99
07-30-2004, 02:04 PM
That fixed it! :D Thanks so much!

Is public_html supposed to be created user.apache? It's created that way every time for me. Not that it really matters because there's only going to be one account on this server - not web hosting, just a personal site and DA is worth the $10 a month for making updates and adding emails easier.

Thank you!

skruf
07-30-2004, 02:13 PM
Hey,

Glad it works...

I'm not really sure about public_html...

Looking over the stuff you posted I saw this:

[2004-07-30 19:34:05]: error: target uid/gid (501/501) mismatch with directory (501/103) or program (0/0)

And took a guess from there... (^:

David

jlasman
07-31-2004, 10:10 AM
Earliest versions of DA created the public_html directory as user:user

Current versions of DA create the public_html directory as user:apache

Since DA is dynamically updated, you may have both settings on your server depending on when the sites were created.

This is definitely an issue to be brought to the attention of DA staff, as I don't recall why it was changed.

I'll bring the post to their attention.

Jeff

thuskey
07-31-2004, 10:22 AM
I'm sure it was changed because the default user is apache and the default group is apache. Without the directory group being set to apache, you can not use http://x.x.x.x/~user/