LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-04-2003, 09:36 PM   #1
lonny
Member
 
Registered: Nov 2003
Posts: 46

Rep: Reputation: 15
Can only get test.cgi to work?


I am trying to run cgi scripts.. here is the 1st one it works fine.
------------------------------------------------------------------------------
#!/usr/bin/perl

# your httpd.conf should have something like this:

# Alias /perl/ /real/path/to/perl-scripts/

# <Location /perl>
# SetHandler perl-script
# PerlHandler Apache::Registry
# PerlSendHeader On
# Options +ExecCGI
# </Location>

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

print "<b>Date: ", scalar localtime, "</b><br>\n";

print "<hr><h1>It worked!</h1>\n";
print "This script runs under: ".$ENV{"GATEWAY_INTERFACE"}."<hr></n";

$ENV{"SERVER_NAME"}="(Hidden for security purposes)";
$ENV{"SERVER_ADMIN"}="(Hidden for security purposes)";
$ENV{"SCRIPT_FILENAME"}="(Hidden for security purposes)";
$ENV{"SERVER_SOFTWARE"}="(Hidden for security purposes)";
$ENV{"SERVER_PORT"}="(Hidden for security purposes)";
$ENV{"SERVER_SIGNATURE"}="Apache-AdvancedExtranetServer (Complete info hidden)";
$ENV{"PATH"}="(Hidden for security purposes)";
$ENV{"SERVER_ADDR"}="(Hidden for security purposes)";
$ENV{"DOCUMENT_ROOT"}="(Hidden for security purposes)";
$ENV{"MOD_PERL"}="(Hidden for security purposes)";


print "%ENV: <br>\n", map { "$_ = $ENV{$_} <br>\n" } keys %ENV;
--------------------------------------------------------------------------------

Here is the second

#!/usr/bin/perl

#start.cgi

use CGI qw(:standard);

print(header());
print(start_html());
print('<body bgcolor="black">');
print(hr());
print('<img src = "../pictures/xboxwp.gif" alt = "xboxwp.gif" />');
print(hr());
print(br());
print('<font color="green">Im a new user:</font> ');

print(br());
print(a({href=> "newUser.cgi", style => "color:#999999"}, "Sign me up" ));
print(br());

print(start_form( -method => "get", -action => "/~lonnborg/webProject/cgi/existingUser.cgi"));
print('<font color="green"> ID: </font>');
print(br());
print(textfield(-name => "user"));
print(br());
print('<font color="green">Password: </font>');
print(br());
print(textfield(-name => "password"));
print(br());
print(br());
print(submit(-value => "Submit"));
print(end_form());
print(end_html());
-----------------------------------------------------------------------------------

When i link to the 2nd one instead of running the cgi script it asks me if i want to download the file?

Last edited by lonny; 12-07-2003 at 02:39 AM.
 
Old 12-05-2003, 03:37 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Is it in the cgi-bin or a directory with ExecCGI enabled?

Have you set the correct file permissions?
 
Old 12-07-2003, 02:38 AM   #3
lonny
Member
 
Registered: Nov 2003
Posts: 46

Original Poster
Rep: Reputation: 15
Well yeah. I put all my cgi files in the cgi-bin directory. Test.cgi and index.cgi are both in the cgi-bin dir. When i run test.cgi it calls the perl program to run the script but when i run index.cgi instead of running the script explorer asks me if i want to download the file. As far as file permissions i did a chmod 777 on the folder. Im not really sure which .conf file to edit. There is 3 of them httpd2.conf, commonhttpd.conf, and httpd2-perl.conf? But if the test script work shouldnt any other script? Is it a problem with my code?
 
Old 12-07-2003, 11:38 AM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
It doesn't seem to be the code but check the fiel permissions. Post the output of:
ls -la /path/to/cgi-bin
 
Old 12-08-2003, 01:25 PM   #5
lonny
Member
 
Registered: Nov 2003
Posts: 46

Original Poster
Rep: Reputation: 15
Here im am logged in as "mike" who runs the server.
-------------------------------------------------------------------
bash-2.05b$ ls -la /var/www/cgi-bin
total 20
drwxrwxrwx 2 root root 4096 Dec 4 13:03 .
drwxrwxrwx 7 root root 4096 Dec 4 11:04 ..
-rw-r--r-- 1 mike mike 793 Dec 4 11:10 index.cgi
-rw-r--r-- 1 mike mike 803 Dec 4 19:44 INDEX.CGI
-rwxr-xr-x 1 root root 1075 Sep 15 21:55 test.cgi
bash-2.05b$

Here im am logged in as "root"
---------------------------------------
[root@webserver root]# ls -la /var/www/cgi-bin
total 20
drwxrwxrwx 2 root root 4096 Dec 4 13:03 ./
drwxrwxrwx 7 root root 4096 Dec 4 11:04 ../
-rw-r--r-- 1 mike mike 793 Dec 4 11:10 index.cgi
-rw-r--r-- 1 mike mike 803 Dec 4 19:44 INDEX.CGI
-rwxr-xr-x 1 root root 1075 Sep 15 21:55 test.cgi*
[root@webserver root]#


It looks like your right about the permissions. I have a Windows machine which i use to edit the cgi scripts. I do a dos2unix on the file and then ftp it over to the linux server. This procedure must not correctly set file permissions? If so what would be the correct command to set correct permissions for index.cgi? Would I have to do this for every new file?
Thanks for the help!
 
Old 12-09-2003, 01:40 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
You need to make them executeable:
chmod 755 /var/www/cgi-bin/*

If it is a shared server it is more secure to only let the webserver user run them:
chmod 755 /var/www/cgi-bin
chmod 754 /var/www/cgi-bin/*
chown -R apache /var/www/cgi-bin
 
Old 12-09-2003, 01:45 PM   #7
lonny
Member
 
Registered: Nov 2003
Posts: 46

Original Poster
Rep: Reputation: 15
I actually did make them executible in cuteftp. I set the file to 755. The script still didnt run. Also I was messing around changing permisssions and such and now test.cgi doesnt run! Im making the problem worse. I think that i need to make a webserver user because that is all i use my linux box for? Are there any tutorials on how to make a webserver user? What groups would I need to make this user part of and what folders would he have to own. I was just thinking of running the server off of root because I really want to start programming. Thanks for the help.


Edit: so if i log in as root and use the commands u wrote above for webserver user u think it should work?

Last edited by lonny; 12-09-2003 at 01:52 PM.
 
Old 12-09-2003, 01:55 PM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
It should also work with 755. Your webserver is already running as a user. This is usually "apache" but older versions used "nobody". You can find out by looking at the User and Group directives in httpd.conf
 
Old 12-11-2003, 12:51 AM   #9
lonny
Member
 
Registered: Nov 2003
Posts: 46

Original Poster
Rep: Reputation: 15
Yep, changed user to mike and it works great thanks for the help!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Yast acting funny DFA SUSE / openSUSE 2 05-23-2005 04:33 PM
sound acting funny madmax04 Fedora 6 10-19-2004 10:20 PM
Gnome acting very funny Stan the caddy Linux - Software 6 09-18-2004 02:57 PM
Directory permissions acting funny... ifm Linux - Newbie 1 06-11-2002 03:18 PM
My Suse box is acting strange, hack or just traffic? skarlet Linux - Security 3 01-17-2002 04:34 PM


All times are GMT -5. The time now is 11:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration