Apache CGI Perl error encountered and resolved

本文详细介绍了如何配置Apache服务器以支持Perl CGI脚本,并解决了权限问题、脚本头异常结束等常见错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tested the Apache CGI perl encountered quite a few problem and solved,

1, configure the /etc/httpd/conf/httpd.conf

uncomment the line as:

AddHandler cgi-script .cgi .pl


get the the access right of the CGI directory, add below lines,

<Directory "/var/www/html/cgi">
Options +ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>


Restart the httpd

/etc/init.d/httpd restart

mkdir /var/www/html/cgi


2, create the perl scripts, helloworld.pl and change the access condition of the perl script

chmod a+x helloworld.pl


3, (13)Permission denied: exec of '/var/www/html/cgi/helloworld.pl' failed

this error caused by selinux, use the command to change folder Selinux security context:

chcon -R -t httpd_sys_script_exec_t /var/www/html/cgi

result as:

[root@localhost cgi]# ll -Z
-rwxr-xr-x. root   root   unconfined_u:object_r:httpd_sys_script_exec_t:s0 helloworld.pl

4, Premature end of script headers

not familiar about the perl language, not sure about the error cause, might caused by the perl command

added the below line, solved, weird,


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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值