cgi perl scripts not working, only cgi bash scripts are working?

為{幸葍}努か 提交于 2019-12-04 22:36:55

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!