LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices


Reply
  Search this Thread
Old 07-01-2004, 01:36 AM   #1
izmir
LQ Newbie
 
Registered: Jul 2004
Location: izmir
Posts: 1

Rep: Reputation: 0
Unhappy CGI problem, works at the command line, but not on the browser


My hello world script works perfect at command line however causes an "internal server error" when I try to view it by browser. I run a Fedora Linux with Plesk 7.

I uploaded it in ASCII mode for sure.

CHMOD is 755.

Below is th result of "ls -la" command:
(For security reasons, I renamed domaincom part)
---------------------------------------------------------------------
drwxr-x--- 2 domaincom psaserv 4096 Jun 30 18:34 .
drwxr-xr-x 14 root root 4096 Jun 29 23:54 ..
-rwxr-xr-x 1 domaincom psacln 83 Jun 30 18:35 hello_world.cgi
-rwxr-xr-x 1 domaincom psacln 83 Jun 30 18:35 hello_world.pl
---------------------------------------------------------------------

The first line which is the path to Perl is correct.
The first output is a heder which indicates this is an HTML code.
Below is the code which inside hello_world.cgi
---------------------------------------------------------------------
#!/usr/bin/perl

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

print "Hello, World...\n";

---------------------------------------------------------------------


./hello_world.cgi works fine
Below is the result when I run "./hello_world.cgi" command:
---------------------------------------------------------------------
content-type: text/html

Hello, World...
---------------------------------------------------------------------


perl hello_world.cgi works fine
Below is the result when I run "perl hello_world.cgi" command:
---------------------------------------------------------------------
content-type: text/html

Hello, World...
---------------------------------------------------------------------

I get an internal server error message when I try to see it with the browser.

In the error log for the domain, it says "Premature end of script headers:" for this request.

In the suexec_log, I have the following lines: (For security reasons, I renamed ftpusername and domain.com parts)

[2004-07-01 08:12:12]: uid: (10001/ftpusername) gid: (10001/10001) cmd: hello_world.cgi
[2004-07-01 08:12:12]: command not in docroot (/data/httpd/vhosts/domain.com/cgi-bin/hello_world.cgi)

I am sure you know how I feel. Any help is appreciated.

Thank you.
 
Old 07-01-2004, 07:19 AM   #2
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
Did you create this file on Windows? If so, it is probably a CR/LF problem. I see this a lot. Try doing...

vi -b scriptname

If you see a bunch of ^M characters at the end of each line, delete those and try it again.
 
Old 07-01-2004, 07:30 AM   #3
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
Uhhh.... forget that. LOL... I just reread your post. I think it is in fact a suexec problem. You need to move that script under the document root of the virtual host it belongs under.

For suexec to work when you run it under the browser, you've got to have the script located under the appropriate document root for whatever virtual host you plan to run it under. For example, let's say you've got a vhost created for yourdomain.com. In that vhost stanza, you've got document root setup to be /home/whatever/html. Your script needs to be located somewhere under that directory.

Last edited by Donboy; 07-01-2004 at 07:32 AM.
 
Old 10-02-2005, 10:10 PM   #4
wilson757
LQ Newbie
 
Registered: Dec 2004
Location: San diego or the sea on LHA-5
Posts: 24

Rep: Reputation: 15
Quote:
Originally posted by Donboy
Uhhh.... forget that. LOL... I just reread your post. I think it is in fact a suexec problem. You need to move that script under the document root of the virtual host it belongs under.

For suexec to work when you run it under the browser, you've got to have the script located under the appropriate document root for whatever virtual host you plan to run it under. For example, let's say you've got a vhost created for yourdomain.com. In that vhost stanza, you've got document root setup to be /home/whatever/html. Your script needs to be located somewhere under that directory.
i am having the same problem. can you please explain how to move that script under the document root of the virtual host it belongs under? thank you for your time.
 
Old 10-02-2005, 11:16 PM   #5
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
Let's say for example you've got a virtual host setup for /home/yourdomain/www. You'll need to create a cgi-bin under /home/yourdomain/www/cgi-bin and move your script under there. You'll also need to add ExecCGI to your options so that cgi scripts can be executed under the new cgi-bin you've created.
 
Old 10-02-2005, 11:47 PM   #6
wilson757
LQ Newbie
 
Registered: Dec 2004
Location: San diego or the sea on LHA-5
Posts: 24

Rep: Reputation: 15
i am so lost...i have tryed to configure it, but i keep getting error 500. </Directory>http://digitalunknown.net/first.pl
# Virtual host Default Virtual Host
<VirtualHost *:80 *:8080>
DocumentRoot /var/www/html
ServerName digitalunknown.net
AddHandler cgi-script .cgi
AddHandler cgi-script .php
AddHandler cgi-script .pl
ServerSignature email
</VirtualHost>

<Directory "/">
Options FollowSymLinks

AllowOverride None



</Directory>

<Directory "/var/www/html">
Options Indexes Includes FollowSymLinks

AllowOverride None
Allow from all


Order allow,deny
</Directory>

<Directory "/var/www/icons">
Options Indexes MultiViews

AllowOverride None
Allow from all


Order allow,deny
</Directory>

<Directory "/usr/share/squirrelmail/">
Options ExecCGI
AddHandler cgi-script .php
AddHandler cgi-script .pl
AddHandler cgi-script .cgi
AllowOverride None
Allow from all


Order allow,deny
</Directory>

<Directory "/var/www/html">
Options ExecCGI
AddHandler cgi-script .php
AddHandler cgi-script .pl
AddHandler cgi-script .cgi
AllowOverride None
Allow from all
Order allow,deny
</Directory>

<Directory "/var/www/usage">
Options ExecCGI

AllowOverride None
Allow from all


Order allow,deny
</Directory>

<Directory "/var/www/cgi-bin">
Options ExecCGI

AllowOverride None
Allow from all


Order allow,deny
 
Old 10-03-2005, 12:02 AM   #7
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
First thing, you have <Directory "/var/www/html"> listed twice. This could be creating a conflict. I suggest removing the second instance and keeping the first.

Also, you can just put your AddHandler statements somewhere near the top of your httpd.conf file and you don't have to specify them under each virtual host. You're putting them multiple times in your config file which is just a waste of code. Just put it somewhere near the top of your conf file and it will apply to the whole server, which is good.

Down near the bottom, you have a statement for <Directory "/var/www/cgi-bin">, which is a step in the right direction, but I believe in order for suexec to work, the directory needs to be created under /var/www/html/cgi-bin, chmod that to 755 and also change the line in your config file to match and restart the server and see if that fixes it.
 
Old 10-03-2005, 12:41 AM   #8
wilson757
LQ Newbie
 
Registered: Dec 2004
Location: San diego or the sea on LHA-5
Posts: 24

Rep: Reputation: 15
ok, so the virtual host i #'ed out gave me the test page, but i got it back with original texted. for the 755 i looked at http://www.digitalunknown.net/pic/linux/help.png I also edited the <directory> and still nothing

#
# Virtual hosts
#

# Virtual host Default Virtual Host
#<VirtualHost *:80 *:8080>
#DocumentRoot /var/www/html
#ServerName digitalunknown.net
#AddHandler cgi-script .cgi .php .pl
#ServerSignature email
#</VirtualHost>
<VirtualHost *:80 *:8080>
ServerSignature email

DirectoryIndex index.php index.html index.htm index.shtml
</VirtualHost>

<Directory "/">
Options FollowSymLinks

AllowOverride None



</Directory>

<Directory "/var/www/html">
Options Indexes Includes FollowSymLinks ExecCGI

AddHandler cgi-script .cgi .php .pl .php

AllowOverride None
Allow from all


Order allow,deny
</Directory>

<Directory "/var/www/icons">
Options Indexes MultiViews

AllowOverride None
Allow from all


Order allow,deny
</Directory>

<Directory "/var/www/usage">
Options ExecCGI

AllowOverride None
Allow from all


Order allow,deny
</Directory>

<Directory "/var/www/html/cgi-bin">
Options ExecCGI

AllowOverride None
Allow from all


Order allow,deny
</Directory>
 
Old 10-03-2005, 12:56 AM   #9
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
No, the virtual host that says

<VirtualHost *:80 *:8080>

Should be uncommented. That one is good. However, you should make it look like this instead.

<VirtualHost *>

Since the single star is all you need. The * covers everything. Putting the ports is unnecessary.

For the block beginning with this...

<Directory "/var/www/html">

I wouldn't enable ExecCGI unless you really need to execute cgi scripts from this directory. Better to enable ExecCGI only in the directory that needs it.

In the block where you put...

<Directory "/var/www/html/cgi-bin">

You've enabled ExecCGI and that's good.

I'm not familiar with the interface you're using, but I recommend doing it at the commend line. Much easier to specify this way.

First you need to run the command...

chmod 755 /var/www/html/cgi-bin

Then you need to make your virtual host container look like this...

<VirtualHost *>
DocumentRoot /var/www/html
ServerName digitalunknown.net
AddHandler cgi-script .cgi
AddHandler cgi-script .php
AddHandler cgi-script .pl
ServerSignature email
SuexecUserGroup username groupname
</VirtualHost>

Notice all I did was add the line for "SuexecUserGroup" and put the user and group. You must change these. "username" and "groupname" will not work. These need to be a real user and group of that user account.

So what I mean is, you need to have a user account that governs this virtual host. For example, let's say you add the following user using the following command...

useradd wilson

Now you have the user and group both named "wilson". So in that case, your line needs to look like this...

SuexecUserGroup wilson wilson

once you have done this, you need to chown everything so it will work. You can do that using this command...

chown -R wilson.wilson /var/www/html

That's it.
 
Old 10-03-2005, 01:01 AM   #10
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
Oops, I missed something here... You'll need to change the "wilson" home directory. Just edit /etc/passwd and change the directory to /var/www/html and it should work.

In my setup, I've got all user accounts running under /home. So you can add new users like this...

useradd joe

Then you'll have a home directory under /home/joe. Now you can add more directories under there, like /home/joe/www/html (etc etc). So your virtual host would be like this...

<VirtualHost *>
DocumentRoot /home/joe/www/html
ServerName somedomain.net
SuexecUserGroup joe joe
</VirtualHost>
 
Old 10-03-2005, 01:24 AM   #11
wilson757
LQ Newbie
 
Registered: Dec 2004
Location: San diego or the sea on LHA-5
Posts: 24

Rep: Reputation: 15
i saw that the cgi-bin was not in the html, but rather the www folder so i changed the dir and Directory. when i added the "SuexecUserGroup root root" it game me this as service httpd start.

[root@digitalunknown /]# cd var
[root@digitalunknown var]# cd www
[root@digitalunknown www]# cd html
[root@digitalunknown html]# cd cgi-bin
bash: cd: cgi-bin: No such file or directory
[root@digitalunknown html]# ls
blahdocs favicon.ico hello.jpg index.htm music text
c first.pl i index.htm~ pic usage
[root@digitalunknown html]# cd ..
[root@digitalunknown www]# chmod 755 /var/www/cgi-bin
[root@digitalunknown www]# chown -R root.root /var/www/html
[root@digitalunknown www]#


<Directory "/var/www/cgi-bin">
Options ExecCGI

AllowOverride None
Allow from all


Order allow,deny
</Directory>


<VirtualHost *>
DocumentRoot /var/www/html
ServerName digitalunknown.net
AddHandler cgi-script .cgi
AddHandler cgi-script .php
AddHandler cgi-script .pl
ServerSignature email
SuexecUserGroup root root <************line1025
</VirtualHost>

[root@digitalunknown ~]# service httpd start
Starting httpd: Syntax error on line 1025 of /etc/httpd/conf/httpd.conf:
Invalid command 'SuexecUserGroup', perhaps mis-spelled or defined by a module not included in the server configuration
[FAILED]
[root@digitalunknown ~]#
 
Old 10-03-2005, 01:29 AM   #12
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
Hmm, it sure smells like you don't have suexec enabled.

Try running this command...

apachectl -l

That is a lowercase L. It should list all of the modules built into apache. However, you can also load modules using the config file. I'm doing it using a line in my config file that looks like this (somewhere near the top)...

LoadModule suexec_module modules/mod_suexec.so

Also, I don't think apache will allow you to run suexec as root. This is a security risk and using root is bad, bad, bad. You should not be running anything under apache as root. If you do, it makes your machine very hackable.
 
Old 10-03-2005, 01:50 AM   #13
wilson757
LQ Newbie
 
Registered: Dec 2004
Location: San diego or the sea on LHA-5
Posts: 24

Rep: Reputation: 15
ok so here is what my vhost looks like now, its running(httpd). i put the test for my mods in here too. also this is what my selinix looks like http://www.digitalunknown.net/pic/linux/help.png btw, i am on aim @ wilson757

<VirtualHost *>
DocumentRoot /var/www/html
ServerName digitalunknown.net
AddHandler cgi-script .cgi
AddHandler cgi-script .php
AddHandler cgi-script .pl
ServerSignature email
DirectoryIndex index.php index.html index.htm index.shtml
SuexecUserGroup bftt bftt
</VirtualHost>





#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule access_module modules/mod_access.so
LoadModule auth_module modules/mod_auth.so
LoadModule auth_anon_module modules/mod_auth_anon.so
LoadModule auth_dbm_module modules/mod_auth_dbm.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule auth_ldap_module modules/mod_auth_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule asis_module modules/mod_asis.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule imap_module modules/mod_imap.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule cgi_module modules/mod_cgi.so


[root@digitalunknown www]# apachectl -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c
[root@digitalunknown www]#
 
Old 10-03-2005, 01:58 AM   #14
wilson757
LQ Newbie
 
Registered: Dec 2004
Location: San diego or the sea on LHA-5
Posts: 24

Rep: Reputation: 15
wow, now my pic/tour04 veiws the file and the pic/linux will not
 
Old 10-03-2005, 01:59 AM   #15
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
Sorry, I dont do instant messaging.

Looks like everything is correct. I think now you'll want to look at your logs and get a better idea of what is wrong. Check out /var/log and somewhere under there you should get a better idea of what is wrong. Each time you get an error in the browser, an error message is being logged to a log file. The trick is knowing where the log files are. There should be a statement somewhere in your config file that tells where the log messages should go. But normally they are somewhere under /var/log/httpd.

I'm not familiar with selinux, but I believe it is supposed to enhance the security of your desktop computer. Since this will be a server, I think you may need to turn this off, but again, I'm no expert with selinux, so better check into this before you do something rash.
 
  


Reply



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
need to control a browser from the command line nephish Linux - Software 6 11-21-2005 05:55 PM
command line web browser chingyenccy Linux - Newbie 4 05-06-2005 07:41 AM
PERL script OK at command line, not in browser alvo Programming 4 12-19-2004 08:28 AM
Command line version of Hardware Browser? weshutchins Linux - Hardware 2 09-22-2004 03:24 PM
Command-Line Browser JoshSmith41 Linux - Software 6 01-08-2004 12:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora

All times are GMT -5. The time now is 12:17 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
Open Source Consulting | Domain Registration