in Linux

Apache CGI Perl error encountered and resolved

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


Restart the httpd

/etc/init.d/httpd restart

mkdir /var/www/html/cgi


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

chmod a+x


3, (13)Permission denied: exec of ‘/var/www/html/cgi/’ 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

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”;

2903total visits,1visits today

Write a Comment


15 + three =