CentOS 7
Sponsored Link

Apache httpd : Use Perl Scripts2014/07/18

 
Enable CGI executing and use Perl scripts.
[1] Install Perl.
[root@www ~]#
yum -y install perl perl-CGI
[2] By default, CGI is allowed under the "/var/www/cgi-bin" directory.
It's possible to use Perl Scripts to put under the directory. All files under it is processed as CGI, though.
# the settings below is the one for CGI

[root@www ~]#
grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf

247: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
[3] If you'd like to allow CGI in other directories, configure like follows.
For example, allow in "/var/www/html/cgi-enabled".
[root@www ~]#
vi /etc/httpd/conf.d/cgi-enabled.conf
# create new

# processes .cgi and .pl as CGI scripts

<Directory "/var/www/html/cgi-enabled">
    Options +ExecCGI
    AddHandler cgi-script .cgi .pl
</Directory>
[root@www ~]#
systemctl restart httpd

[4] If SELinux is enabled and also allow CGI under directories which is not the default like [3] above, change rules like follows.
[root@www ~]#
chcon -R -t httpd_sys_script_exec_t /var/www/html/cgi-enabled

[root@www ~]#
semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled

[5] Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown.
[root@www ~]#
vi /var/www/html/cgi-enabled/index.cgi
#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "<html>\n<body>\n";
print "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">\n";
print "CGI Test Page";
print "\n</div>\n";
print "</body>\n</html>\n";

[root@www ~]#
chmod 705 /var/www/html/cgi-enabled/index.cgi

Matched Content