i am having strange problem.,
from command line cgi bash scripts and cgi perl scripts are working , but from browser only cgi bash scripts are working and not the cgi perl .
after accessing cgi perl scripts from browser i get 500 Internal server error .
and apache error log says
[Thu Oct 25 01:58:59 2012] [error] [client x.x.x.x] (13)Permission denied: exec of '/home/x/x/x/x/public_html/cgi-bin/test.cgi' failed
[Thu Oct 25 01:58:59 2012] [error] [client x.x.x.x] Premature end of script headers: test.cgi
i want to run cgi perl scripts from browser .
how do i do it.
[root@www ~]# which perl
/usr/bin/perl
[root@www cgi-bin]# perl test.cgi
Content-type: text/plain
testing...
source of test.cgi
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "testing...\n";
Thanks for your time.
its a dedicated server with apache 2.
As mentioned by Barmar, you probably have a permissions issue. Also, since you are just getting started, here is an improved test script:
#!/usr/bin/perl
use strict;
use warnings;
#Useful for testing: Perl error messages, plus your die statements, will get
#sent to the browser. Otherwise you will just see "Internal Server Error".
use CGI::Carp qw/fatalsToBrowser/;
#Always use the CGI module for your scripts.
use CGI;
#Create simple HTML output (taken directly from CGI documentation).
my $q = CGI->new; # create new CGI object
print $q->header, # create the HTTP header
$q->start_html('hello world'), # start the HTML
$q->h1('hello world'), # level 1 header
$q->end_html; # end the HTML
Please see the documentation on CGI for more information.
Also, for clarification: the "Premature End of Script Headers" error means that your script sent no output to the browser. In this case, it is because your script didn't run. However, it could also happen if your script runs but doesn't actually send any output. It is a useful error to know about.
Did you set permissions correctly for the perl script? Compare them with the permissions you set for the bash script.
Maybe chmod 755
would help as suggested here (unfortunately German only)
check which user is running httpd by
[root@www ~]# top | grep httpd
15607 apache 16 0 210m 19m 4228 S 23.5 0.2 0:00.52 httpd
in above the apache user is running.
try su apache,
confirm you are apache by using command whoami ,
if you havent switched to apache then this means no shell is assigned to user apache,
now modify /etc/passwd file
find user apache and change ending from
/bin/false
to
/bin/bash
save passwd file , then try su apache, check with whoami, if you successfully switched to user apache then go to the directory where the script is located and try to run it from there.
you will get something like
bash: /usr/bin/perl: Permission denied
this means user "apache" does not have permissions to user perl.
you need to add permissions to execute perl script to user "apache".
***dont forget to change the passwd file as it was previously.
you can do that by adding a group to specific user and changing the group name httpd.conf.
thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.